import sys from heapq import heappop, heappush input = sys.stdin.readline def main(): INF = 10 ** 18 N, M, X = map(int, input().split()) edges = [[] for i in range(N)] edges_a = [[] for i in range(N)] edges_b = [[] for i in range(N)] bs = [] for i in range(M): u, v, a, b = map(int, input().split()) u -= 1 v -= 1 edges[u].append(v) edges_a[u].append(a) edges_b[u].append(b) edges[v].append(u) edges_a[v].append(a) edges_b[v].append(b) bs.append(b) bs.sort() ok = -1 ng = N while ng - ok > 1: md = (ng + ok) // 2 m = bs[md] dist = [INF] * N hq = [] heappush(hq, 0) dist[0] = 0 f = 0 while hq: now = heappop(hq) % (10 ** 9) for i in range(len(edges[now])): b = edges_b[now][i] if b < m: continue nxt = edges[now][i] a = edges_a[now][i] if dist[nxt] <= dist[now] + a: continue dist[nxt] = dist[now] + a heappush(hq, dist[nxt] * (10 ** 9) + nxt) if nxt == N - 1 and dist[-1] <= X: f = 1 break if f: ok = md else: ng = md if ok == -1: print(-1) else: print(bs[ok]) if __name__ == '__main__': main()