import scala.math.abs

object Main extends App {
  val sc = new java.util.Scanner(System.in) 
  val N = sc.nextInt()
  val P = Vector.fill(N)(sc.nextInt())
  val Q = Vector.fill(N)(sc.nextInt())
  val permutations = (1 to N).permutations.toList
  val a = permutations.indexOf(P) + 1
  val b = permutations.indexOf(Q) + 1
  println(abs(a - b))
}

