import sys ONLINE_JUDGE = sys.argv[-1] == 'ONLINE_JUDGE' if not ONLINE_JUDGE and len(sys.argv)>1 and sys.argv[1]!="<": sys.stdin = open(sys.argv[1], "r", encoding="utf-8") import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) if "pypyjit" in sys.builtin_module_names: import pypyjit pypyjit.set_param("max_unroll_recursion=-1") 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))