n,m,X=map(int,input().split()) e=[[] for i in range(n)] for i in range(m): u,v,a,b=map(int,input().split()) u-=1 v-=1 e[u]+=[(v,a,b)] e[v]+=[(u,a,b)] from heapq import heappush,heappop ok=-1 ng=10**10 while ng-ok>1: m=(ok+ng)//2 v=[X+1]*n v[0]=0 q=[(0,0)] while len(q)>0: sc,sp=heappop(q) if sc!=v[sp]: continue for tp,tc,tw in e[sp]: if tw>=m: if v[tp]>sc+tc: v[tp]=sc+tc heappush(q,(v[tp],tp)) if v[n-1]<=X: ok=m else: ng=m print(ok)