from heapq import heappop, heappush 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)] 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) ok = -1 ng = INF while ng - ok > 1: m = (ng + ok) // 2 dist = [INF] * N hq = [] heappush(hq, (0, 0)) dist[0] = 0 while hq: _, now = heappop(hq) for i in range(len(edges[now])): nxt = edges[now][i] a = edges_a[now][i] b = edges_b[now][i] if b < m: continue if dist[nxt] > dist[now] + a: dist[nxt] = dist[now] + a heappush(hq, (dist[nxt], nxt)) if dist[-1] > X: ng = m else: ok = m print(ok)