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<>()); } for (int i = 0; i < mm; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; int d = sc.nextInt(); 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); } } int left = 0; int right = Integer.MAX_VALUE / 2; PriorityQueue queue = new PriorityQueue<>(); int[] costs = new int[n]; while (right - left > 1) { int m = (left + right) / 2; queue.add(new Path(0, 0)); check(m, costs, queue); if (costs[n - 1] == Integer.MAX_VALUE) { right = m; for (int i = 1; i < n; i++) { if (costs[i] != Integer.MAX_VALUE) { queue.add(new Path(i, 0)); } } } else { left = m; } } queue.add(new Path(0, 0)); check(left, costs, queue); System.out.println(left + " " + costs[n - 1]); } 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(); } }