from heapq import heapify, heappush, heappop n, c, v = map(int, (input() for _ in range(3))) connections = [set() for _ in range(n + 1)] for s, t, y, m in zip(*(map(int, input().split()) for _ in range(4))): connections[s].add((m, t, y)) queue = [(*con, c - con[2]) for con in connections[1] if con[2] <= c] heapify(queue) while queue: m, t, y, c = heappop(queue) if t == n: print(m) break for nm, nt, ny in connections[t]: if c < ny: continue heappush(queue, (m + nm, nt, ny, c - ny)) else: print(-1)