include [HTML_REMOVED]
include [HTML_REMOVED]
const int N = 1e3 + 5, P = 2e4 + 5, PosInf = 1e9;
struct Edge
{
int to, w;
int next;
}edges[P];
int n, p, k, dis[N], cost[P];
int head[N], total;
bool in[N];
void Add(int u, int v, int w)
{
edges[total].to = v;
edges[total].w = w;
edges[total].next = head[u];
head[u] = total++;
}
void Spfa(int start)
{
std::queue[HTML_REMOVED] q;
for (int i = 0; i < N; i++)
{
dis[i] = PosInf;
in[i] = false;
}
dis[start] = 0;
in[start] = true;
q.push(start);
while (!q.empty())
{
int t = q.front();
q.pop();
in[t] = false;
for (int i = head[t]; i != -1; i = edges[i].next)
{
int v = edges[i].to, w = cost[i];
if (dis[v] > dis[t] + w)
{
dis[v] = dis[t] + w;
if (!in[v])
{
q.push(v);
in[v] = true;
}
}
}
}
}
bool Check(int x)
{
for (int i = 1; i <= n; i++)
{
for (int j = head[i]; j != -1; j = edges[j].next)
{
if (edges[j].w <= x)
cost[j] = 0;
else cost[j] = 1;
}
}
Spfa(1);
return dis[n] <= k;
}
int main()
{
for (int i = 0; i < N; i++)
head[i] = -1;
int wMax = -PosInf;
std::cin >> n >> p >> k;
for (int i = 1; i <= p; i++)
{
int a, b, c;
std::cin >> a >> b >> c;
wMax = std::max(c, wMax);
Add(a, b, c);
Add(b, a, c);
}
int l = 0, r = wMax, mid = 0;
while (l < r)
{
mid = (l + r) >> 1;
if (Check(mid))
r = mid;
else l = mid + 1;
}
if (l == wMax) std::cout << -1 << std::endl;
else std::cout << l << std::endl;
return 0;
}