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 = { if (exp == 0) 1 else { (if (exp % 2 == 1) base else 1) * powMod(base * base % MOD, exp / 2) % MOD } } }