#include <cstring>
#include <iostream>
#include <bitset>
#include <vector>
#include <queue>
struct Edge
{
int to, nxt, w;
};
struct Node
{
int u, w;
friend bool operator>(Node a, Node b) { return a.w > b.w; }
};
int n, p, k, cnt_edge;
int dis[1005], head[1005];
Edge edge[100005];
std::bitset<1005> vis;
std::bitset<100005> t;
std::priority_queue<Node, std::vector<Node>, std::greater<Node>> pq;
void add_edge(int u, int v, int w)
{
edge[cnt_edge].to = v;
edge[cnt_edge].w = w;
edge[cnt_edge].nxt = head[u];
head[u] = cnt_edge++;
}
void dijkstra()
{
memset(dis, 0x3f, 4 * (n + 1));
dis[1] = 0;
pq.push({1, 0});
while (!pq.empty())
{
int u = pq.top().u;
pq.pop();
if (u == n)
return;
if (vis[u])
continue;
vis[u] = true;
for (int i = head[u]; i != -1; i = edge[i].nxt)
{
int v = edge[i].to, w = t[i];
if (dis[v] > dis[u] + w)
{
dis[v] = dis[u] + w;
pq.push({v, dis[v]});
}
}
}
}
bool check(int x)
{
vis.reset();
for (int i = 0; i < cnt_edge; i++)
t[i] = edge[i].w > x;
while (!pq.empty())
pq.pop();
dijkstra();
return dis[n] <= k;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int l, r, ans = -1;
std::cin >> n >> p >> k;
memset(head, -1, sizeof(int) * (n + 1));
for (int i = 1; i <= p; i++)
{
int a, b, l;
std::cin >> a >> b >> l;
add_edge(a, b, l);
add_edge(b, a, l);
}
l = 0, r = 1000000;
while (l <= r)
{
int m = (l + r) / 2;
if (check(m))
{
ans = m;
r = m + 1;
}
else
l = m + 1;
}
std::cout << ans << "\n";
return 0;
}