#include <bits/stdc++.h>
using namespace std;
const int N = 505, M = 10005;
int n, m, k, dis[N], backup[N];
struct Node{
int a, b, w;
}edge[M];
int bellman_ford(){
memset(dis, 0x3f, sizeof(dis));
dis[1] = 0;
for(int i = 0; i < k; i++){
memcpy(backup, dis, sizeof(dis));
for(int j = 0; j < m; j++){
int a = edge[j].a, b = edge[j].b, w = edge[j].w;
dis[b] = min(dis[b], backup[a] + w); //备份,防止原来的数据被覆盖
}
}
if(dis[n] > 0x3f3f3f3f / 2) return -1;
return dis[n];
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i = 0; i < m; i++){
int a, b, w;
scanf("%d%d%d",&a,&b,&w);
edge[i] = {a, b, w};
}
int t = bellman_ford();
if(t == -1) puts("impossible");
else printf("%d\n", t);
}