from collections import deque def is_ok(arg): p = l[arg] w = BWS(p) 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)] se = set([]) for s,t,d in z: V[s].append([t,d]) V[t].append([s,d]) se.add(d) l = list(se) l = [0] + sorted(l) + [10**18] M = len(l) ans = meguru_bisect(M, 0) print(l[ans], BWS(l[ans]))