n,m = map(int,input().split()) a = 10**10 for i in range(m): u,v,w = map(int,input().split()) a = min(a,w) print(n)