N=int(input())
P=list(map(int,input().split()))

c=[]
for i in range(N):
    if P[i]==i+1:
        c.append(i+1)

import sys
if c==[]:
    print(0)
    sys.exit()

d=[]
for i in range(1,len(c)):
    d.append(c[i]-c[i-1])

if len(c)==2:
    print(c[1]-c[0])
elif len(c)%2==0:
    print(sum(d)-max(d))
else:
    print(sum(d)-max(d)+1)