MOD = 998244353 def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 if N >= 3: for _ in range(M): x = int(input[ptr]) ptr += 1 y = int(input[ptr]) ptr += 1 z = int(input[ptr]) ptr += 1 if (x + y) % 2 != z: print(0) return print(1 % MOD) elif N == 2: fixed = {} has_conflict = False for _ in range(M): x = int(input[ptr]) ptr += 1 y = int(input[ptr]) ptr += 1 z = int(input[ptr]) ptr += 1 if (x, y) in fixed: if fixed[(x, y)] != z: has_conflict = True else: fixed[(x, y)] = z if has_conflict: print(0) return sum_fixed = 0 for val in fixed.values(): sum_fixed += val F = 4 - len(fixed) if F == 0: if sum_fixed % 2 == 0: print(1) else: print(0) else: ways = pow(2, F - 1, MOD) print(ways) elif N == 1: if M == 0: print(2 % MOD) else: z_list = [] for _ in range(M): x = int(input[ptr]) ptr += 1 y = int(input[ptr]) ptr += 1 z = int(input[ptr]) ptr += 1 if x != 1 or y != 1: print(0) return z_list.append(z) z_set = set(z_list) if len(z_set) == 1: print(1 % MOD) else: print(0) if __name__ == '__main__': main()