import numpy as np from scipy.sparse.csgraph import dijkstra from scipy.sparse import csr_matrix 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=dijkstra(csgraph=csr_matrix(a),indices=0) if sp[n-1]<=0: print(str(dmax-l)+" "+str(sp[n-1])) break