import scala.io.StdIn._
object Main extends App {

  val n: Int = readInt()
  val p = readLine().split(" ").map(_.toInt).toSeq
  val q = readLine().split(" ").map(_.toInt).toSeq

  def solve() = {
    val permutations = (1 to n).permutations.toList
    (permutations.indexOf(p) - permutations.indexOf(q)).abs
  }


  println(solve())

}
