fun main(args: Array<String>) {
    val N = nextInt()
    val P = listOfInt(-1).joinToString(separator = "")
    val Q = listOfInt(-1).joinToString(separator = "")
    val A = IntArray(N)
    val R = mutableListOf<String>()
    fun Permutation(n: Int) {
        if (n == N) {
            R.add(A.joinToString(separator = ""))
        } else {
            for (m in 0 until N) {
                if (A.slice(0 until n).all { it != m }) {
                    A[n] = m
                    Permutation(n + 1)
                }
            }
        }
    }
    Permutation(0)
    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 }
