import java.io.PrintWriter import scala.collection.mutable.* import scala.io.StdIn.* import scala.util.chaining.* import scala.math.* import scala.reflect.ClassTag import scala.util.* import scala.annotation.tailrec import scala.collection.mutable inline val MOD = 998244353 extension (base: Long) def powMod(exp: Long): Long = var result = 1L var b = base % MOD var e = exp while e > 0 do if (e & 1) == 1 then result = result * b % MOD b = b * b % MOD e >>= 1 result.toInt @main def main = val Array(n, m) = readLine().split(' ').map(_.toInt) val row = readLine().split(' ').map(_.toInt) val column = readLine().split(' ').map(_.toInt) if row.fold(0)(_ ^ _) == column.fold(0)(_ ^ _) then println((1 << 20).powMod((n - 1L) * (m - 1L))) else println(0)