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

//movingCount < 10^9
//1回以上movingCount以下の回数の抽選を行う
//最初にコマをおいたあと移動する場所はpn[i]に記載されている
//移動回数分数値がベタガキされていく →　再帰関数
fun solve(pn: List<Int>): Int {
    return createNewList(pn)
}

fun createNewList(pn: List<Int>): Int {
    tailrec fun innerFunction(index: Int, list: List<Int>, movingCountSum: Int): Int {
        return if (list.withIndex().all { it.value - 1 != it.index }) movingCountSum
        else {
            val newList = if (list[index] == index + 1) {
                val beforeList = list.subList(0, index)
                val afterList = list.subList(index + 1, pn.size)
                listOf(*beforeList.toTypedArray(), list[index + 1], list[index], *afterList.toTypedArray())
            } else {
                list
            }
            val currentMovingCount = if (newList != list) 1 else 0

            innerFunction(index + 1, newList, movingCountSum + currentMovingCount)
        }
    }

    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()!!
}