def BFS(): q = [(0, 0)] wid = [-1] * N wid[0] = float('inf') while q: new = [] for i, t in q: for j, a, b in e[i]: if wid[j] < min(wid[i], b) and t + a <= X: new.append((j, t+a)) wid[j] = min(wid[i], b) q = new return wid N, M, X = map(int, input().split()) e = [[] for _ in range(N)] for _ in range(M): u, v, a, b = map(int, input().split()) u -= 1 v -= 1 e[u].append((v, a, b)) e[v].append((u, a, b)) wid = BFS() print(wid[-1])