import java.io.*; import java.util.*; public class Main { static ArrayList> graph = new ArrayList<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int mm = sc.nextInt(); for (int i = 0; i < n; i++) { graph.add(new HashMap<>()); } PriorityQueue roads = new PriorityQueue<>(); for (int i = 0; i < mm; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; int d = sc.nextInt(); roads.add(new Road(a, b, d)); if (!graph.get(a).containsKey(b) || graph.get(a).get(b) < d) { graph.get(a).put(b, d); } if (!graph.get(b).containsKey(a) || graph.get(b).get(a) < d) { graph.get(b).put(a, d); } } UnionFindTree uft = new UnionFindTree(n); Road r = null; while (!uft.same(0, n - 1)) { r = roads.poll(); uft.unite(r); } PriorityQueue queue = new PriorityQueue<>(); int[] costs = new int[n]; queue.add(new Path(0, 0)); check(r.weight, costs, queue); System.out.println(r.weight + " " + 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(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 weight; public Road(int left, int right, int weight) { this.left = left; this.right = right; this.weight = weight; } public int compareTo(Road r) { return r.weight - weight; } } static void check(int size, int[] costs, PriorityQueue queue) { 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).keySet()) { if (graph.get(p.idx).get(x) < size) { continue; } queue.add(new Path(x, p.value + 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; } } } 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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }