import heapq inf = 1 << 61 def dijkstra(s, n, edge): dist = [inf]*n dist[s] = 0 hq = [[0,s]] heapq.heapify(hq) while len(hq) > 0: d,i = heapq.heappop(hq) if dist[i] < d: continue for j,d_1 in edge[i]: if dist[j] > (dist[i] + d_1): dist[j] = dist[i] + d_1 heapq.heappush(hq, [dist[j],j]) return dist N,M,X = map(int,input().split()) G = [[] for i in range(N)] for i in range(M): u,v,c,t = map(int,input().split()) d = c + t*X u -= 1 v -= 1 G[u].append((v,d)) G[v].append((u,d)) dist = dijkstra(0,N,G) if dist[N-1] == inf: print(-1) exit() ans = dist[N-1] // X if dist[N-1] % X: ans += 1 print(ans)