n=int(input())
p=list(map(int,input().split()))
cnt=0
tmp=[]
for i in range(0,n):
    if p[i]==i+1:
        tmp.append(p[i])

for i in range(len(tmp)-1):
    if i%2==0 :
        cnt+=tmp[i+1]-tmp[i]

print(cnt)