from heapq import * INF = 10**18 def dijkstra(g, s, n): dist = [INF]*n hq = [(0, s)] dist[s] = 0 while hq: d, v = heappop(hq) if dist[v]!=d: continue for to, c in g[v]: if dist[v] + c < dist[to]: dist[to] = dist[v] + c heappush(hq, (dist[to], to)) return dist n, m, x = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(m): u,v,c,t = list(map(int, input().split())) u -= 1 v -= 1 g[u].append((v,t*x+c)) g[v].append((u,t*x+c)) dist = dijkstra(g, 0, n) if dist[-1] == INF: print(-1) else: print((dist[-1] + x-1)//x)