program A321C
    implicit none
    integer(8)::N,i,ocount,ans
    integer(8),allocatable,dimension(:)::P,L
    read*,N
    allocate(P(N))
    allocate(L(N))
    read*,P
    L=0
    ans=0

    do i=1,N
        if(P(i)==i)L(i)=1
    end do

    ocount=0
    do i=1,N
        if(L(i)==1)then
            ocount=ocount+1
        else
            if(ocount==1)ans=ans+1
            if(ocount>1)ans=ans+ocount-1
            ocount=0
        end if
    end do
    if(ocount==1)ans=ans+1
    if(ocount>1)ans=ans+ocount-1
    
    print'(i0)',ans
end program A321C