N,M = map(int,input().split()) std = [tuple(map(int,input().split())) for _ in range(M)] dst = [(d,s-1,t-1) for (s,t,d) in std] dst.sort() from collections import defaultdict,deque import sys sys.setrecursionlimit(10**6) v = deque() def is_ok(x): e = defaultdict(list) for i in range(M-1,-1,-1): d,s,t = dst[i] if d1: mid = (y+x)//2 if is_ok(mid): x = mid else: y = mid print(x,is_ok(x))