n = int(input())
p = list(map(int,input().split()))
count = 0
memo = {}
for i in range(n):
  if p[i]==i+1:
    count=count+1
    continue
  else:
    if count == 0:
      continue
    else:
      if count not in memo:
        memo[count]= 1
        count = 0
      else:
        memo[count]+=1
  count = 0
  
if count == 0:
  count = 0
else:
  if count not in memo:
    memo[count]= 1
  else:
    memo[count]+=1

ans = 0 
for i in memo:
  if i ==1:
    ans = ans+memo[i]
  else:
    ans = ans+(i-1)*memo[i]
print(ans)