from heapq import heapify, heappop, heappush N, M, X = map(int, input().split()) G = [[] for _ in range(N)] 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)) H = [(0, 0)] heapify(H) dist = [10 ** 18] * N dist[0] = 0 while len(H) > 0: d, u = heappop(H) if d > dist[u]: continue for v, w in G[u]: if dist[v] > dist[u] + w: dist[v] = dist[u] + w heappush(H, (dist[v], v)) if dist[N - 1] == 10 ** 18: print(-1) else: print((dist[N - 1] + X - 1) // X)