import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {
    static class Edge {
        int v,w,d;
        Edge(int v,int w,int d) {
            this.v = v;
            this.w = w;
            this.d = d;
        }
    }
    static void solve() {
        int n=in.nextInt(),m=in.nextInt(),h=in.nextInt();
        List<List<Edge>> graph = new ArrayList<>();
        for(int i=0;i<=n;i++) {
            graph.add(new ArrayList<>());
        }
        for(int i=0;i<m;i++) {
            int u = in.nextInt(),v=in.nextInt(),w=in.nextInt(),d=in.nextInt();
            graph.get(u).add(new Edge(v,w,d));
            graph.get(v).add(new Edge(u,w,d));
        }
        PriorityQueue<int[]> pq = new PriorityQueue<>(Comparator.comparingInt(a -> a[0]));
        pq.add(new int[] {-Integer.MAX_VALUE,1,0});
        
        int[] dis = new int[n+1];
        Arrays.fill(dis,Integer.MIN_VALUE);
        dis[1] = Integer.MAX_VALUE;
        
        while(!pq.isEmpty()) {
            int[] cur = pq.poll();
            int res = -cur[0];
            int node = cur[1];
            int dist = cur[2];
            if(res<dis[node]) continue;
            for(Edge edge : graph.get(node)) {
                if(dist+edge.d>h) continue;
                int newWeight = Math.min(res,edge.w);
                if(newWeight>dis[edge.v]) {
                    dis[edge.v]=newWeight;
                    pq.add(new int[] {-newWeight,edge.v,dist+edge.d});
                }
            }
        }
        out.println(dis[n]==Integer.MIN_VALUE?-1:dis[n]);
    }

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    static FastReader in = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    static class FastReader {
        static BufferedReader br;
        static StringTokenizer st;

        FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            String str = "";
            while (st == null || !st.hasMoreElements()) {
                try {
                    str = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                st = new StringTokenizer(str);
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}