from collections import deque import sys input = sys.stdin.readline INF = 1 << 30 n, m = map(int, input().split()) edge = [[] for _ in range(n)] for _ in range(m): s, t, d = map(int, input().split()) s -= 1 t -= 1 edge[s].append((t, d)) edge[t].append((s, d)) left, right = 1, 10**9 + 10 while right - left > 1: mid = (left + right) // 2 Que = deque([0]) seen = set([0]) C = [INF] * n C[0] = 0 while Que: cp = Que.popleft() if cp == n - 1: break cnt = C[cp] for np, w in edge[cp]: if w < mid: continue if cnt + 1 > C[np]: continue if np in seen: continue seen.add(np) C[np] = cnt + 1 Que.append(np) if C[n - 1] < INF: left = mid else: right = mid Que = deque([0]) seen = set([0]) C = [INF] * n C[0] = 0 while Que: cp = Que.popleft() if cp == n - 1: print(left, C[cp]) break cnt = C[cp] for np, w in edge[cp]: if w < left: continue if cnt + 1 > C[np]: continue if np in seen: continue seen.add(np) C[np] = cnt + 1 Que.append(np)