#int(input()) #map(int, input().split()) #list(map(int, input().split())) N, M, X = map(int, input().split()) to = [[] for i in range(N)] for i in range(M): u, v, a, b = map(int, input().split()) to[u-1].append((v-1, a, b)) to[v-1].append((u-1, a, b)) import heapq ans = -1 v = [-1] * N v[0] = 10 ** 9 q = [(-(10**9), 0, 0)] heapq.heapify(q) c = 1 while q: s, x, t = heapq.heappop(q) s *= -1 # print(s, x, t) if v[x] > s: continue for y, a, b in to[x]: if t + a > X: continue # if v[y] >= min(b, s): # continue heapq.heappush(q, (-min(b, s), y, t+a)) v[y] = max(min(b, s), v[y]) print(min(v)) # print(v)