N,M=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) MOD = 998244353 ans = 0 for i in range(20): n=sum([(a>>i)&1 for a in A]) m=sum([(b>>i)&1 for b in B]) if (n&1)!=(m&1): print(0) exit() print(pow(pow(pow(2,20,MOD), N-1,MOD),M-1,MOD))