N,M=map(int, input().split()) D=[] for i in range(M): s,t,d=map(int, input().split()) D.append((d,s,t)) D=sorted(D)[::-1] par=[i for i in range(N)] rank=[0]*(N) friend=[0]*N block=[0]*N size=[1]*N def find(x): if par[x]==x: return x else: par[x]=find(par[x]) return par[x] #同じ集合か判定 def same(x,y): return find(x)==find(y) def union(x,y): x=find(x) y=find(y) if x==y: return if rank[x]>rank[y]: par[y]=x size[x]+=size[y] else: par[x]=y size[y]+=size[x] if rank[x]==rank[y]: rank[y]+=1 E=[[]for i in range(N)] for d,s,t in D: s-=1 t-=1 union(s,t) E[s].append(t) E[t].append(s) if same(0,N-1): answ=d break from collections import deque d=deque() d.append((0,0,0)) while d: now,pre,num=d.popleft() for nex in E[now]: if nex==N-1: print(answ,num+1) exit() if nex!=pre: d.append((nex,now,num+1))