fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val list = getVariation(n)
    val p = readLine()!!
    val q = readLine()!!
    val ans = Math.abs(list.indexOf(q) - list.indexOf(p))
    println(ans)
}

fun getVariation(len:Int):List<String> {
    val tmp = getVariationSub((1..len).toList())
    return tmp.map { it.joinToString(" ") }
}

fun getVariationSub(remain:List<Int>):List<List<Int>> {
    if(remain.size == 1) {
        return listOf(listOf(remain.first()))
    }
    val ret = mutableListOf<List<Int>>()
    for(i in remain.indices) {
        val newList = remain.indices.filter { it != i }.map { remain[it] }
        val tmp = getVariationSub(newList).toMutableList().map { it.toMutableList() }
        tmp.forEach { it.add(0, remain[i]) }
        ret.addAll(tmp)
    }
    return ret
}