n,m=map(int,input().split()) edge=[[] for i in range(n)] for i in range(m): s,t,d=map(int,input().split()) s-=1;t-=1 edge[s].append((t,d*-1)) edge[t].append((s,d*-1)) from heapq import heappop,heappush def dijkstra(s,n,edge): inf=float("inf") ans=[inf]*n ans[s]=0 root=[0]*n open=[[-inf,s]] while open: cost,node=heappop(open) if ans[node]=0: continue visited[node]=value for next,tmp in edge[node]: if -border>=tmp and visited[next]==-1: que.append((next,value+1)) print(border,visited[-1])