#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; #define rep(i,m,n,k) for (int i = (int)(m); i < (int)(n); i += (int)(k)) #define rrep(i,m,n,k) for (int i = (int)(m); i > (int)(n); i += (int)(k)) #define ll long long #define list(T,A,N) vector A(N);for(int i=0;i<(int)(N);i++){cin >> A[i];} template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} using modint = modint998244353; int main(){ ll N,M; cin >> N >> M; list(ll,A,N); list(ll,B,M); ll ta=0; ll tb=0; for(auto a:A){ ta ^= a; } for(auto b:B){ tb ^= b; } if (ta!=tb){ cout << 0 << endl; return 0; } ll L = 20*(N-1)*(M-1); ll ans = 1; ans = pow_mod(2,L,998244353); cout << ans << endl; return 0; }