import heapq N, M, X = map(int, input().split()) adj_list = [] for _ in range(M): u,v,a,b = map(int, input().split()) adj_list.append([u,v,a,b]) small = -1 large = 10**9 + 1 while(large-small>1): middle = (large + small)//2 #print(large, middle, small) # 大きさmiddleのようかんをX分以内に輸送できるか? adj = [[] for _ in range(N)] for u,v,a,b in adj_list: if middle <= b: adj[u-1].append((v-1, a)) adj[v-1].append((u-1, a)) new_adj = [] for l in adj: p = {} for v,a in l: if v in p.keys(): p[v] = min(p[v], a) else: p[v] = a new_adj.append([(v,p[v]) for v in p.keys()]) adj = new_adj times = [-1 for _ in range(N)] q = [(0, 0)] heapq.heapify(q) #print(adj) while(len(q)>0): time, node = heapq.heappop(q) if times[node]==-1: times[node] = time for v, d in adj[node]: heapq.heappush(q, (time+d, v)) #print(times) if times[N-1]==-1 or times[N-1]>X: #運べなかった large = middle else: #運べた small = middle print(small)