n, m = map(int, input().split()) assert(2 <= n <= 500) assert(m == n * (n - 1) // 2) edges = set() for i in range(m): u, v, w = map(int, input().split()) assert(1 <= u <= n) assert(1 <= v <= n) assert(u != v) assert(w == 1) edges.add((min(u, v), max(u, v))) f = True try: input() f = False except: pass assert(f) assert(len(edges) == m)