fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var p = readLine()!!.split(' ').map { it.toInt() }
    var q = readLine()!!.split(' ').map { it.toInt() }
    var a = 0
    var b = 0
    var cnt = 0

    fun dfs(list: List<Int>) {
        if (list.size < n) {
            (1..n).forEach { if (!list.contains(it)) dfs(list + it) }
            return
        }
        cnt++
        if (list == p) a = cnt
        if (list == q) b = cnt
    }
    dfs(listOf())

    println(Math.max(a-b, b-a))
}
