import scala.io.StdIn.readLine object Main { def main(args: Array[String]): Unit = { val Array(n, m) = readLine().split(" ").map(_.toLong) val row = readLine().split(" ").map(_.toInt) val column = readLine().split(" ").map(_.toInt) if (row.fold(0)(_ ^ _) == column.fold(0)(_ ^ _)) { println(powMod(1 << 20, (n - 1) * (m - 1))) } else { println(0) } } val MOD = 998244353; def powMod(base : Long, exp : Long): Long = { var result = 1L var b = base % MOD var e = exp while (e > 0) { if ((e & 1) == 1) { result = result * b % MOD } b = b * b % MOD e /= 2 } result } }