from collections import deque def is_ok(w): # 条件を満たすかどうか?問題ごとに定義 que = deque([(0,0)]) visited = [float('inf')]*N visited[0] = 0 while que: t,c = que.popleft() for i,j in l[t]: if w > j or c+1 >= visited[i]: continue visited[i] = c+1 que.append((i,c+1)) if visited[-1] == float('inf'): visited[-1] = -1 return visited[-1] def meguru_bisect(ng, ok): ''' 初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す まずis_okを定義すべし ng ok は とり得る最小の値-1 とり得る最大の値+1 最大最小が逆の場合はよしなにひっくり返す ''' num = 0 while (abs(ok - ng) > 1): mid = (ok + ng) // 2 flg = is_ok(mid) if flg != -1: ng = mid num = flg else: ok = mid return (ng,num) N,M = map(int,input().split()) l = [[] for _ in range(N)] for _ in range(M): a,b,c = map(int,input().split()) a -= 1 b -= 1 l[a].append((b,c)) l[b].append((a,c)) ng,ok = 0,10**9 ans = meguru_bisect(ng,ok) print(ans[0],ans[1])