#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; template< int mod > struct Fp { int x; Fp() : x(0) {} Fp(int64_t y) : x(y >= 0 ? y % mod : (mod + y % mod) % mod) {} Fp &operator+=(const Fp &p) { if((x += p.x) >= mod) x -= mod; return *this; } Fp &operator-=(const Fp &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } Fp &operator*=(const Fp &p) { x = (int)(1LL * x * p.x % mod); return *this; } Fp &operator/=(const Fp &p) { *this *= p.inv(); return *this; } Fp operator-() const { return Fp(-x); } Fp operator+(const Fp &p) const { return Fp(*this) += p; } Fp operator-(const Fp &p) const { return Fp(*this) -= p; } Fp operator*(const Fp &p) const { return Fp(*this) *= p; } Fp operator/(const Fp &p) const { return Fp(*this) /= p; } bool operator==(const Fp &p) const { return x == p.x; } bool operator!=(const Fp &p) const { return x != p.x; } Fp inv() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return Fp(u); } Fp pow(int64_t n) const { Fp ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const Fp &p) { return os << p.x; } friend istream &operator>>(istream &is, Fp &a) { int64_t t; is >> t; a = Fp< mod > (t); return (is); } static int get_mod() { return mod; } }; using mint = Fp<998244353>; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N,M; cin >> N >> M; vector A(N), B(M); rep(i,N) cin >> A[i]; rep(i,M) cin >> B[i]; mint ans = 1; mint p2 = mint(2).pow((N - 1) * (M - 1)); rep(b,20) { ll A_xor = 0, B_xor = 0; rep(i,N) A_xor ^= !!(A[i] & (1 << b)); rep(i,M) B_xor ^= !!(B[i] & (1 << b)); ans *= (A_xor == B_xor ? p2 : 0); } cout << ans << endl; }