############################################################################################ import bisect,collections,copy,heapq,itertools,math,string,sys,queue,time,random from decimal import Decimal def I(): return input() def IS(): return input().split() def II(): return int(input()) def IIS(): return list(map(int,input().split())) def LIIS(): return list(map(int,input().split())) def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] import math def prime_numbers(n): prime = [True for i in range(n+1)] prime[0] = False prime[1] = False sqrt_n = math.ceil(math.sqrt(n)) for i in range(2, sqrt_n): if prime[i]: for j in range(2*i, n+1, i): prime[j] = False numbers=[] for i in range(2,n+1): if prime[i]: numbers.append(i) return numbers def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr INF=1<<63 MOD=998244353 MOD2=10**9+7 sys.setrecursionlimit(500005) alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ" def bit_count(x): return bin(x).count("1") def yesno(f): if f:print("Yes") else:print("No") #################################################### l=-1 r=10**10 n,m,x=IIS() path=[[] for i in range(n)] for _ in range(m): u,v,a,b=IIS() path[u-1].append((v-1,a,b)) path[v-1].append((u-1,a,b)) def is_ok(val): q=[(0,0)] costs=[INF for i in range(n)] costs[0]=0 while q: c,v=heapq.heappop(q) for i,j,k in path[v]: if costs[i]k:continue heapq.heappush(q,(c+j,i)) costs[i]=c+j return costs[n-1]<=x while r-l>1: mid=(r+l)//2 if is_ok(mid): l=mid else: r=mid print(l)