#include using namespace std; using ll = long long; constexpr ll mod = 998244353; ll mod_pow(ll a, ll b) { if (!b) return 1; if (b & 1) return mod_pow(a, b - 1) * a % mod; return mod_pow(a * a % mod, b >> 1); } int main() { ll N, M; cin >> N >> M; ll x = 0; for (int i = 0; i < N + M; ++i) { ll a; cin >> a; x ^= a; } if (x != 0) puts("0"); else cout << mod_pow(2, 60 * (N - 1) * (M - 1)) << endl; }