from heapq import heappop, heappush from collections import defaultdict n, m, x = map(int, input().split()) G = defaultdict(list) for _ in range(m): u, v, c, t = map(int, input().split()) u -= 1 v -= 1 G[u].append((v, c + t * x)) G[v].append((u, c + t * x)) INF = 10**18 DP = [INF for _ in range(n)] DP[0] = 0 H = [(0, 0)] while H: cc, cp = heappop(H) if cc > DP[cp]: continue for np, dc in G[cp]: nc = cc + dc if nc >= DP[np]: continue DP[np] = nc heappush(H, (nc, np)) ans = DP[n - 1] if ans == INF: ans = -1 else: ans = (ans + x - 1) // x print(ans)