import java.util.*; import java.io.*; public class Main { static FastScanner sc = new FastScanner(System.in); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(); static ArrayList> G = new ArrayList<>(); static ArrayList arr = new ArrayList<>(); public static void main(String[] args) throws Exception { solve(); pw.flush(); } public static void solve() { int N = sc.nextInt(); int E = sc.nextInt(); DSU dsu = new DSU(N); for(int i = 0; i < N; i++){ G.add(new ArrayList<>()); } for (int i = 0; i < E; i++) { int a = sc.nextInt()-1; int b = sc.nextInt()-1; long d = sc.nextLong(); arr.add(new Edge(a,b,d)); } Collections.sort(arr); long ans = (long)1e10; for(int i = 0; i < E; i++){ Edge e = arr.get(i); ans = e.max; dsu.merge(e.from,e.to); G.get(e.from).add(e); G.get(e.to).add(e); if(dsu.same(0,N-1)){ ans = e.max; break; } } PriorityQueue pq = new PriorityQueue<>(); pq.add(new Point(0,0)); int[] min = new int[N]; Arrays.fill(min,(int)1e9); min[0] = 0; while(pq.size() > 0){ Point p = pq.poll(); if(p.now == N-1){ pw.println(ans + " " + p.cnt); return; } if(min[p.now] < p.cnt){ continue; } min[p.now] = p.cnt; for(Edge e : G.get(p.now)){ if(min[e.to] <= p.cnt+1) continue; pq.add(new Point(e.to,p.cnt+1)); } } } static class GeekInteger { public static void save_sort(int[] array) { shuffle(array); Arrays.sort(array); } public static int[] shuffle(int[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); int randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } public static void save_sort(long[] array) { shuffle(array); Arrays.sort(array); } public static long[] shuffle(long[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); long randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } } static class Point implements Comparable{ int now, cnt; public Point(int now, int cnt) { this.now = now; this.cnt = cnt; } public int compareTo(Point p){ if(this.cnt < p.cnt){ return -1; }else if(this.cnt > p.cnt){ return 1; }else{ return 0; } } } static class Edge implements Comparable{ int from, to; long max; public Edge(int from, int to, long max) { this.from = from; this.to = to; this.max = max; } public int compareTo(Edge e){ if(this.max > e.max){ return -1; }else if(this.max < e.max){ return 1; }else{ return 0; } } } } class DSU { private int n; private int[] parentOrSize; private java.util.ArrayList> map; public DSU(int n) { this.n = n; this.map = new java.util.ArrayList>(); for (int i = 0; i < n; i++) { this.map.add(new java.util.ArrayList()); this.map.get(i).add(i); } this.parentOrSize = new int[n]; java.util.Arrays.fill(parentOrSize, -1); } int merge(int a, int b) { if (!(0 <= a && a < n)) throw new IndexOutOfBoundsException("a=" + a); if (!(0 <= b && b < n)) throw new IndexOutOfBoundsException("b=" + b); int x = leader(a); int y = leader(b); if (x == y) return x; if (-parentOrSize[x] < -parentOrSize[y]) { int tmp = x; x = y; y = tmp; } parentOrSize[x] += parentOrSize[y]; parentOrSize[y] = x; this.map.get(x).addAll(this.map.get(y)); return x; } boolean same(int a, int b) { if (!(0 <= a && a < n)) throw new IndexOutOfBoundsException("a=" + a); if (!(0 <= b && b < n)) throw new IndexOutOfBoundsException("b=" + b); return leader(a) == leader(b); } int leader(int a) { if (parentOrSize[a] < 0) { return a; } else { parentOrSize[a] = leader(parentOrSize[a]); return parentOrSize[a]; } } int size(int a) { if (!(0 <= a && a < n)) throw new IndexOutOfBoundsException("" + a); return -parentOrSize[leader(a)]; } java.util.ArrayList> groups() { int[] leaderBuf = new int[n]; int[] groupSize = new int[n]; for (int i = 0; i < n; i++) { leaderBuf[i] = leader(i); groupSize[leaderBuf[i]]++; } java.util.ArrayList> result = new java.util.ArrayList<>(n); for (int i = 0; i < n; i++) { result.add(new java.util.ArrayList<>(groupSize[i])); } for (int i = 0; i < n; i++) { result.get(leaderBuf[i]).add(i); } result.removeIf(java.util.ArrayList::isEmpty); return result; } java.util.ArrayList getArray(int n) { return this.map.get(n); } } class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public FastScanner(FileReader in) { reader = new BufferedReader(in); tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String[] nextArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = next(); return a; } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } }