import collections N,M = map(int,input().split()) lsg = [[] for i in range(N)] for i in range(M): s,t,d = map(int,input().split()) s -= 1 t -= 1 lsg[s].append((t,d)) lsg[t].append((s,d)) INF = float('INF') def is_ok(arg): d = collections.deque([0]) used = [False]*(N) cost = [INF]*N cost[0] = 0 while d: x = d.popleft() if used[x]: continue used[x] = True for y,c in lsg[x]: if used[y]: continue if (cost[y] > cost[x] + 1) and (arg <= c): cost[y] = cost[x] + 1 d.append(y) return used[N-1] 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 w = meguru_bisect(10**18+1,0) d = collections.deque([0]) used = [False]*(N) cost = [INF]*N cost[0] = 0 while d: x = d.popleft() if used[x]: continue used[x] = True for y,c in lsg[x]: if used[y]: continue if (cost[y] > cost[x] + 1) and (w <= c): cost[y] = cost[x] + 1 d.append(y) print(w,cost[N-1])