N,M,X = map(int, input().split()) edge = [[] for i in range(N)] for i in range(M): u,v,c,t = map(int, input().split()) u-=1;v-=1 edge[u].append((v,(t+c/X)*10**12)) edge[v].append((u,(t+c/X)*10**12)) from heapq import * INF = 10**24 def dijkstra(N, edge, s): dist = [INF] * N que = [(0, s)] dist[s] = 0 while que: c, v = heappop(que) if dist[v] < c: continue for t, cost in edge[v]: if dist[v] + cost < dist[t]: dist[t] = dist[v] + cost heappush(que, (dist[t], t)) return dist import math d = dijkstra(N,edge,0) ans = d[-1] print(math.ceil(ans/10**12) if ans != INF else -1)