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

ans = 0
flag = 0

tmp = 0
for n in range(N):
  if p[n] == n+1:
    if flag == 0:
      tmp = n
      flag = 1
    else:
      ans += n - tmp
      flag = 0
print(ans)