var R = mutableListOf<String>()
fun main(args: Array<String>) {
    val N = nextInt()
    val P = listOfInt().joinToString(separator = "")
    val Q = listOfInt().joinToString(separator = "")
    var A = mutableListOf<Int>()
    for (n in 1..N) A.add(n)
    permutation(A.toIntArray())
    var p = 0
    var q = 0
    for (a in R) {
        if (a == P) break;
        p += 1
    }
    for (a in R) {
        if (a == Q) break;
        q += 1
    }
    println(Math.abs(p - q))
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun permutation(seed: IntArray) {
    val perm = IntArray(seed.size)
    val used = BooleanArray(seed.size)
    buildPerm(seed, perm, used, 0)
}
fun buildPerm(seed: IntArray, perm: IntArray, used: BooleanArray, index: Int) {
    if (index == seed.size) {
        procPerm(perm)
        return
    }
    for (i in seed.indices) {
        if (used[i]) continue
        perm[index] = seed[i]
        used[i] = true
        buildPerm(seed, perm, used, index + 1)
        used[i] = false
    }
}
fun procPerm(perm: IntArray) {
    R.add(perm.joinToString(separator = ""))
}