from collections import defaultdict
import numpy as np

n = int(input())
p = np.array(list(map(int, input().split())))

comp = np.arange(n) + 1
diff = comp - p


memo = defaultdict(int)
memo[0] = 0

cnt = 0
for x in diff:
    if x == 0:
        cnt += 1
    else:
        memo[cnt] += 1
        cnt = 0

if diff[-1] == 0:
    memo[cnt] += 1

remove = memo.pop(0)

if memo[1] != 0:
    ans = memo.pop(1)
else:
    ans = 0

for k, v in memo.items():
    ans += (k - 1) * v

print(ans)