from collections import deque n,m=map(int,input().split()) g=[[] for _ in range(n)] W=[] for _ in range(m): s,t,d=map(int,input().split()) s-=1;t-=1 W.append(d) g[s].append([t,d]) g[t].append([s,d]) def bfs(w): dst=[-1]*n dst[0]=0 q=deque() q.append(0) while q: now=q.popleft() for to,limit in g[now]: if limit1: mid=(ok+ng)//2 if bfs(W[mid])!=-1: ok=mid else: ng=mid print(W[ok],bfs(W[ok]))