import sys,math,itertools from collections import Counter,deque,defaultdict from bisect import bisect_left,bisect_right from heapq import heappop,heappush,heapify mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split())) def inps(): return sys.stdin.readline() def inpsl(x): tmp = inps(); return list(tmp[:x]) def err(x): print(x); exit() n,m = inpl() g = [[] for _ in range(n)] for _ in range(m): a,b,d = inpl() g[a-1].append((d,b-1)) g[b-1].append((d,a-1)) def sol(X): dist = [-1]*n; dist[0] = 0 q = deque([0]) while q: u = q.popleft() for d,v in g[u]: if dist[v] != -1 or X > d: continue dist[v] = dist[u] + 1 q.append(v) return dist[n-1] ok = 0 ans = -1 ng = 10**10 while abs(ok-ng) > 1: mid = (ok+ng)//2 res = sol(mid) # print(mid,res) if res > 0: ok = mid ans = res else: ng = mid print(ok,ans)