program prob4
    implicit none
    integer::N, i, ans, mode
    integer, allocatable::p(:)
    read(*,*) N
    allocate(p(N))
    read(*,*) p
    mode = 0
    ans = 0
    do i = 1, N
        if(i > 1 .and. p(i) == i .and. p(i-1) == i-1) then
            if(mode == 0) then
                ans = ans + 1
                mode = 1
            else if(i < N .and. p(i+1) /= i+1) then
                    mode = 0
                    ans = ans + 1
            else if(i == N) then
                ans = ans + 1
            end if
        else if(p(i) == i) then
            if(i == N) then
                ans = ans + 1
            else if(i < N .and. p(i+1) /= i+1) then
                ans = ans + 1
            end if
        end if
    end do

    write(*,*) ans
    deallocate(p)
    stop
end program