local mod = 998244353 local mfl = math.floor local function bmul(x, y) local x0, y0 = x % 31596, y % 31596 local x1, y1 = mfl(x / 31596), mfl(y / 31596) return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % mod end local function modpow(src, pow) local res = 1 while 0 < pow do if pow % 2 == 1 then res = bmul(res, src) pow = pow - 1 end src = bmul(src, src) pow = mfl(pow / 2) end return res end local n, m = io.read("*n", "*n") local a = {} for i = 1, n do a[i] = io.read("*n") end local b = {} for i = 1, m do b[i] = io.read("*n") end for i = 1, 20 do local az = 0 for j = 1, n do az = az + a[j] % 2 a[j] = mfl(a[j] / 2) end local bz = 0 for j = 1, m do bz = bz + b[j] % 2 b[j] = mfl(b[j] / 2) end if (az + bz) % 2 == 1 then print(0) os.exit() end end if n == 1 or m == 1 then print(1) else print(modpow(2, (n - 1) * (m - 1) * 20)) end