import numpy as np n,m=list(map(int,input().split())) li=[[0 for i in range(n)] for j in range(n)] dmax=0 for k in range (m): s,t,d=list(map(int,input().split())) li[s-1][t-1]=d li[t-1][s-1]=d dmax=max(dmax,d) arl=np.array(li) for l in range(dmax): a=np.where(arl>=(dmax-l),1,0) sp,pred=dijkstra(csgraph=csr_matrix(a),directed=False,indices=0,unweighted=True,return_predecessors=True) if pred[n-1]!=-9999: print(str(dmax)+" "+str(pred[n-1])) break