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(); 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); UnionFindTree uft = new UnionFindTree(n); int ans = 0; for (int i = m - 1; i >= 0; i--) { uft.unite(roads[i]); if (uft.same(0, n - 1)) { ans = roads[i].value; break; } } List> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { if (roads[i].value >= ans) { graph.get(roads[i].left).add(roads[i].right); graph.get(roads[i].right).add(roads[i].left); } } Deque deq = new ArrayDeque<>(); deq.add(new Path(0, 0)); int[] costs = new int[n]; Arrays.fill(costs, Integer.MAX_VALUE); 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)); } } System.out.println(ans + " " + costs[n - 1]); } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = IntStream.range(0, size).toArray(); } public int find(int x) { return x == parents[x] ? x : (parents[x] = find(parents[x])); } public boolean same(int x, int y) { return find(x) == find(y); } public boolean same(Road r) { return same(r.left, r.right); } 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); } } 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 value - another.value; } } static class Path { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.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(); } } }