import sys input = sys.stdin.readline from heapq import heappush,heappop INF=1<<60 N,M,X=map(int,input().split()) UVAB=[list(map(int,input().split())) for _ in range(M)] edge = [[] for _ in range(N)] for u,v,a,b in UVAB: u-=1;v-=1 edge[u].append((v,a,b)) edge[v].append((u,a,b)) def check(B): time = [INF]*N time[0]=0 que = [(0,0)] while que: x,v = heappop(que) if time[v]= time[to]:continue time[to]=x2 heappush(que, (x2,to)) if time[-1]<=X:return True return False ok,ng=-1,10**9+1 while ok+1>1 if check(m): ok=m else: ng=m print(ok)