from heapq import heappush, heappop N, M, X = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(M): u, v, C, T = map(int, input().split()) G[u-1].append((v-1, C+T*X)) G[v-1].append((u-1, C+T*X)) INF = 10**18 def dijkstra(start): dist = [INF]*N dist[start] = 0 visited = [False]*N que = [(0, start)] while que: d, now = heappop(que) if visited[now]: continue visited[now] = True for next, weight in G[now]: if dist[now]+weight < dist[next]: dist[next] = dist[now]+weight heappush(que, (dist[next], next)) return dist dist = dijkstra(0) if dist[-1] == INF: print(-1) else: print((dist[-1]+X-1)//X)