import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) 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)] limit=0 for d,s,t in D: #print(s,t,d,limit) if limit>d: break s-=1 t-=1 union(s,t) E[s].append(t) E[t].append(s) if same(0,N-1): answ=d limit=d from collections import deque d=deque() d.append((0,0,0)) F=[N]*N while d: now,pre,num=d.popleft() for nex in E[now]: if nex==N-1: print(answ,num+1) exit() if nex!=pre: if num+1