import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); UnionFindTree uft = new UnionFindTree(n); Road weight = IntStream.range(0, m).mapToObj(i -> new Road(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt())) .sorted() .filter(x -> uft.unite(x)).findFirst().orElse(null); System.out.println(weight.value + " " + uft.getCost()); } static class UnionFindTree { int size; int[] parents; List> graph; public UnionFindTree(int size) { this.size = size; parents = IntStream.range(0, size).map(i -> i).toArray(); graph = IntStream.range(0,size).mapToObj(i -> new ArrayList()).collect(Collectors.toList()); } public int find(int x) { if (x == parents[x]) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public boolean unite(Road r) { if (!same(0, size - 1)) { int left = find(r.left); int right = find(r.right); if (left != right) { parents[left] = right; } graph.get(r.left).add(r.right); graph.get(r.right).add(r.left); } return same(0, size - 1); } public int getCost() { int[] costs = new int[size]; Arrays.fill(costs, Integer.MAX_VALUE); ArrayDeque deq = new ArrayDeque<>(); deq.add(new Path(0, 0)); while (deq.size() > 0) { Path p = deq.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx)) { deq.add(new Path(x, p.value + 1)); } } return costs[size - 1]; } } static class Path { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } } static class Road implements Comparable { int left; int right; int value; public Road(int left, int right, int value) { this.left = left; this.right = right; this.value = value; } public int compareTo(Road another) { return another.value - value; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }