object Main extends App{
  val n = readInt
  val p = readLine.split(" ").toList.map(_.toInt)
  val q = readLine.split(" ").toList.map(_.toInt)
  val l = (1 to n).toList.permutations.toList
  println( (l.indexOf(p)-l.indexOf(q)).abs )
}