import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); Road[] roads = new Road[m]; for (int i = 0; i < m; i++) { roads[i] = new Road(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt()); } Arrays.sort(roads); ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } UnionFindTree uft = new UnionFindTree(n); int ans = 0; for (Road x : roads) { uft.unite(x); graph.get(x.left).add(x.right); graph.get(x.right).add(x.left); if (uft.same(0, n - 1)) { ans = x.weight; break; } } PriorityQueue queue = new PriorityQueue<>(); int[] costs = new int[n]; Arrays.fill(costs, Integer.MAX_VALUE); queue.add(new Path(0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value + 1)); } } System.out.println(ans + " " + costs[n - 1]); } static class Path implements Comparable { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } static class Road implements Comparable { int left; int right; int weight; public Road(int left, int right, int weight) { this.left = left; this.right = right; this.weight = weight; } public int compareTo(Road another) { return another.weight - weight; } } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } 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 void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } public void unite(Road r) { unite(r.left, r.right); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }