from collections import deque def is_ok(arg): w = BWS(arg) return w != 10**18 def meguru_bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok def BWS(w): q = deque([]) reach = [10**18]*(n+1) q.append(1) reach[1] = 0 while q: x = q.popleft() for y,z in V[x]: if reach[y] > reach[x] + 1 and w <= z: q.append(y) reach[y] = reach[x] + 1 return reach[-1] n,m = map(int,input().split()) z = [list(map(int,input().split())) for i in range(m)] V = [[] for i in range(n+1)] for s,t,d in z: V[s].append([t,d]) V[t].append([s,d]) ans = meguru_bisect(10**9 + 1, 0) print(ans, BWS(ans))