import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (1..n).map { sc.nextInt() }
    val b = (1..n).map { sc.nextInt() }
    val permList = genPermList(n, listOf<Int>())
    println(Math.abs(permList.indexOf(a) - permList.indexOf(b)))
}

fun genPermList(n: Int, used: List<Int>): List<List<Int>> {
    val res = mutableListOf<List<Int>>()
    if (used.size == n) {
        res.add(used)
        return res
    }
    for (i in 1..n) {
        if (!used.contains(i)) {
            val nextUsed = mutableListOf<Int>()
            nextUsed.addAll(used)
            nextUsed.add(i)
            res.addAll(genPermList(n, nextUsed))
        }
    }
    return res
}
