#!/bin/bash
read n; read -a p
count=0
prev=0
for (( i = 0; i < n; i++ )); do
    if (( p[i] != i + 1 )); then
        prev=0
    else
        (( prev = ~prev )) && (( ++count ))
    fi
done
echo ${count}
