def binary_search_int(ok,ng,test): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok-ng)>1: mid=(ok+ng)//2 if test(mid): ok=mid else: ng=mid return ok ############################################################## import sys input = sys.stdin.readline INF = 10**18 # 大きい数字 N, M, K = map(int, input().split()) edges=[[] for _ in range(N)] for _ in range(M): x, y, cost = map(int, input().split()) x-=1 y-=1 edges[x].append((y,cost)) edges[y].append((x,cost)) def test(k): next_set=[[] for _ in range(N)] next_set[0]=[0] dist=[INF]*(N+1) for time in range(N): while next_set[time]: p = next_set[time].pop() if dist[p]k: cost=1 else: cost=0 if dist[q]<=time+cost: continue dist[q]=time+cost if q!=N-1: next_set[time+cost].append(q) return dist[N-1]<=K-1 kmin=binary_search_int(10**6,-1,test) print(kmin)