MOD = 998244353 n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 1 for i in range(20): cx = 0 cy = 0 for x in a: if (x >> i) & 1: cx ^= 1 for x in b: if (x >> i) & 1: cy ^= 1 if cx != cy: print(0) exit(0) ans *= pow(2, (n - 1) * (m - 1), MOD) print(ans % MOD)