############################################################# import sys sys.setrecursionlimit(10**7) from heapq import heappop,heappush from collections import deque,defaultdict,Counter from bisect import bisect_left, bisect_right from itertools import product,combinations,permutations ipt = sys.stdin.readline def iin(): return int(ipt()) def lmin(): return list(map(int,ipt().split())) inf = 1<<60 MOD = 998244353 ############################################################# N,M,X = lmin() G = [[] for _ in range(N)] for _ in range(M): u,v,a,b = lmin() u,v = u-1,v-1 G[u].append((v,a,b)) G[v].append((u,a,b)) def check(cen): cost = [inf]*N cost[0] = 0 hq = [] heappush(hq, (0,0)) while hq: t,cur = heappop(hq) if t > cost[cur]: continue for nxt,a,b in G[cur]: if b < cen: continue nt = t+a if nt < cost[nxt]: cost[nxt] = nt heappush(hq, (nt, nxt)) return cost[-1] <= X ok = -1 ng = 1<<30 while ng - ok > 1: cen = (ok+ng)//2 if check(cen): ok = cen else: ng = cen print(ok)