N, M = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = 0 for i in range(N): C ^= A[i] for j in range(M): C ^= B[j] if C == 0: print(pow(2, (N-1) * (M-1) * 60, 998244353)) else: print(0)