from collections import deque n,m=map(int,input().split()) a=[[]for _ in range(m)] for _ in range(m): s,t,d=map(int,input().split()) s,t=s-1,t-1 a[s].append((t,d)) a[t].append((s,d)) q=[] q=deque([]) q.append((10**18,0)) dist=[[0]+[0] for _ in range(n)] dist[0][0]=10**18 while q: dis,now=q.popleft() if dis=v: if dist[next][0]==v: dist[next][1]=min(dist[next][1],dist[now][1]+1) continue dist[next][0]=v dist[next][1]=dist[now][1]+1 q.append((v,next)) print(dist[n-1][0],dist[n-1][1])