#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 510, M = 10010;
int n, m, k;
int dist[N], backup[N];
struct Edge
{
int a, b, w;
}edges[M];
int bellman_ford()
{
memset(dist, 0x3f, sizeof dist); //
dist[1] = 0; // 初始这两行基本不变
for (int i = 0; i < k; i ++) // k 次 循环保证路径上的边数少于n行
{
memcpy(backup, dist, sizeof dist); //每次先备份
for (int j = 0; j < m; j ++)
{
int a = edges[j].a,b = edges[j].b, w= edges[j].w; // 获取每一条边的信息
dist[b] = min(dist[b], backup[a] + w); // 进行松弛操作
}
}
return dist[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);
edges[i] = {a, b, w};
}
int t = bellman_ford();
if (t > 0x3f3f3f3f / 2) puts("impossible");
else printf("%d\n", t);
return 0;
}