import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val n = sc.nextInt

  val p = List.fill(n)(sc.nextInt)
  val q = List.fill(n)(sc.nextInt)

  val permutation = (1 to n).permutations.toVector

  val res = Math.abs(permutation.indexOf(p) - permutation.indexOf(q))

  println(res)


}
