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(); Bridge[] bridges = new Bridge[m]; for (int i = 0; i < m; i++) { bridges[i] = new Bridge(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt()); } Arrays.sort(bridges); UnionFindTree uft = new UnionFindTree(n); int max = 0; for (Bridge x : bridges) { uft.unite(x); if (uft.same(0, n - 1)) { max = x.value; break; } } ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (Bridge x : bridges) { if (x.value >= max) { graph.get(x.left).add(x.right); graph.get(x.right).add(x.left); } } PriorityQueue queue = new PriorityQueue<>(); queue.add(new Path(0, 0)); int[] costs = new int[n]; Arrays.fill(costs, Integer.MAX_VALUE); 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(max + " " + costs[n - 1]); } 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 boolean same(Bridge x) { return same(x.left, x.right); } public void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } public void unite(Bridge b) { unite(b.left, b.right); } } static class Bridge implements Comparable { int left; int right; int value; public Bridge(int left, int right, int value) { this.left = left; this.right = right; this.value = value; } public int compareTo(Bridge another) { return another.value - value; } } 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; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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(); } }