import java.util.*

fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val p = sc.asSequence().take(n).map { it.toInt() }.joinToString("")
    val q = sc.asSequence().take(n).map { it.toInt() }.joinToString("")

    val s = (1..n).map { it.toString() }.joinToString("")
    val all = mutableListOf<String>()
    permutation(s, "", all)
    all.sort()
//    println(p)
//    println(q)
//    println(all)
    print(Math.abs(all.indexOf(q) - all.indexOf(p)))
}

fun permutation(q: String, ans: String, all: MutableList<String>) {
    // Base Case
    if (q.length <= 1) {
        all.add(ans + q)
    } else {
        for (i in 0 until q.length) {
            permutation(
                q.substring(0, i) + q.substring(i + 1),
                ans + q[i],
                all
            )
        }
    }// General Case
}