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