import heapq 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=[] heapq.heapify(q) heapq.heappush(q,(0,-10**18,0)) dist=[[0]*2 for _ in range(n)] dist[0][0]=10**18 while q: distanc,dis,now=heapq.heappop(q) dis=-dis if dis=v: continue dist[next][0]=v dist[next][1]=distanc+1 heapq.heappush(q,(distanc+1,-v,next)) print(dist[n-1][0],dist[n-1][1])