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: MutableList<Int>, movingCountSum: Int): Int {
        return if (index == listLength) {
            movingCountSum
        } else {
            var currentMovingCount2 = 0

            val newList = if (list[index] == index + 1 && index + 1 != listLength) {
                val a = list[index]
                val b = list[index + 1]
                list[index] = b
                list[index + 1] = a
//                val beforeList = if (index == 0) listOf() else list.take(index)
//                val afterList = if (index + 2 == listLength) listOf() else list.takeLast(listLength - index - 2)
                currentMovingCount2++
                list
//                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++
                val a = list[index]
                val b = list[index - 1]
                list[index] = b
                list[index - 1] = a
                list
            } else {
                list
            }
            val newMovingCountSum = movingCountSum + currentMovingCount2
            val newIndex = index + 1

            innerFunction(newIndex, newList, newMovingCountSum)
        }
    }

    return innerFunction(0, pn.toMutableList(), 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()!!
}