from sys import stdin from collections import deque n, m, k, *indata = map(int, stdin.read().split()) offset = 0 g = [[] for i in range(n+1)] for i in range(m): s, t, d = indata[offset + 3*i],indata[offset + 3*i+1],indata[offset + 3*i+2] g[s].append((t,d)) g[t].append((s,d)) que = deque() que.append(1) dist = [0 for i in range(n+1)] check = [0 for i in range(n+1)] check[1] = 1 while que: now = que.popleft() if now == n: break for i, c in g[now]: if check[i] == 0: check[i] = 1 dist[i] = dist[now] + 1 que.append(i) if dist[n] <= k-1: print("{}".format(0)) exit() left = 0 right = 2 * (10**5) + 1 while right - left >= 2: mid = (right + left) // 2 que = deque() que.append((1,0)) dist = [0 for i in range(n+1)] check = [0 for i in range(n+1)] while que: now, d = que.popleft() if check[now] == 0: check[now] = 1 dist[now] = d if now == n: break for i, c in g[now]: if check[i] == 0: if c > mid: que.append((i,d+1)) else: que.appendleft((i,d)) if dist[n] <= k-1: right = mid else: left = mid print("{}".format(right))