#yuki1870 mod=998244353 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 i in range(m): c^=b[i] if c: print(0) exit() print(pow(2,(n-1)*(m-1)*20,mod))