n, m = map(int, input().split()) V = [[] for _ in range(n)] max_d = 0 for _ in range(m): s, t, d = map(int, input().split()) V[s-1].append((t-1, d)) V[t-1].append((s-1, d)) max_d = max(max_d, d) def bfs(w): global n, V B = [False] * n q = [(0, 0)] while len(q) > 0: v, c = q.pop(0) if v == n-1: return c if B[v]: continue B[v] = True for t, d in V[v]: if d >= w: q.append((t, c+1)) return 0 l, r = 0, max_d + 1 while r - l > 1: mid = (l + r) // 2 c = bfs(mid) if c == 0: r = mid else: l = mid print(l, bfs(l))