import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
int h = scanner.nextInt();
List<List<int[]>> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
List<int[]> ele = new ArrayList<>();
list.add(ele);
}
for (int i = 0; i < m; i++) {
int u = scanner.nextInt();
int v = scanner.nextInt();
int w = scanner.nextInt();
int d = scanner.nextInt();
list.get(u - 1).add(new int[]{v,w,d});
list.get(v - 1).add(new int[]{u,w,d});
}
Queue<Map<String,Integer>> queue = new LinkedList<>();
Map<String,Integer> map = new HashMap<>();
map.put(1 + "",1);
map.put("u",1);
map.put("w",Integer.MAX_VALUE);
map.put("d",0);
queue.add(map);
int max = -1;
while (!queue.isEmpty()) {
Map<String,Integer> head = queue.poll();
if (head.get("u") == n) {
if (head.get("w") > max) {
max = head.get("w");
}
continue;
}
Integer u = head.get("u");
List<int[]> ele = list.get(u - 1);
for (int i = 0; i < ele.size(); i++) {
int[] next = ele.get(i);
if (!head.containsKey(next[0]) && next[2] + head.get("d") <= h) {
Map<String,Integer> temp = new HashMap<>(head);
temp.put(next[0] + "",1);
temp.put("u",next[0]);
temp.put("w",Math.min(next[1],temp.get("w")));
temp.put("d",temp.get("d") + next[2]);
queue.add(temp);
}
}
}
System.out.println(max);
}
}

#笔试##23届找工作求助阵地#