fun main() {
    val nk = nextInt()
    val pn = nextIntList()
    val ans = solve(pn)
    println(ans)
}

fun solve(pn: List<Int>): Int {
    val a = createNewList(pn)
    return a
}

fun createNewList(pn: List<Int>): Int {
    val listLength = pn.size

    tailrec fun innerFunction(index: Int, list: List<Int>, movingCountSum: Int): Int {
        return if (index == listLength) {
            movingCountSum
        } else {
//            var currentMovingCount2 = 0
//
//            val newList = if (list[index] == index + 1 && index + 1 != listLength) {
//                val beforeList = if (index == 0) listOf() else list.take(index)
//                val afterList = if (index + 2 == listLength) listOf() else list.takeLast(listLength - index - 2)
//                currentMovingCount2++
//                beforeList.union(listOf(list[index + 1], list[index])).union(afterList).toList()
////                listOf(*beforeList.toTypedArray(), list[index + 1], list[index], *afterList.toTypedArray())
//            } else if (index + 1 == listLength && list[index] == index + 1) {
//                val beforeList = list.take(index - 1)
//                currentMovingCount2++
//                listOf(*beforeList.toTypedArray(), list[index], list[index - 1])
//            } else {
//                list
//            }
//            val newMovingCountSum = movingCountSum + currentMovingCount2
//            val newIndex = index + 1

            innerFunction(index + 1, list, movingCountSum)
        }
    }

    return innerFunction(0, pn, 0)
}


fun nextInt(): Int {
    return readLine()!!.toInt()
}

fun nextIntList(): List<Int> {
    return readLine()!!.split(" ").map { it.toInt() }
}

fun nextLongList(): List<Long> {
    return readLine()!!.split(" ").map { it.toLong() }
}

fun nextString(): String {
    return readLine()!!
}