#include #include using namespace std; using Mint = atcoder::modint998244353; int main() { int N, M; cin >> N >> M; int r = 0; for (int i = 0; i < N + M; ++i) { int t; cin >> t; r ^= t; } if (!r) cout << Mint(2).pow(20LL * (N - 1) * (M - 1)).val() << endl; else cout << 0 << endl; }