import sys
sys.setrecursionlimit(10000)
n = int(input())
ls = list(map(int,input().split()))
di = []
ans = 0 
def culc(n):
    if n == 1:
        return 1
    elif n == 2:
        return 1
    else:
        if n % 2 == 0:
            a = culc(n//2) * 2
        else:
            a = culc(n//2) + culc((n//2) + 1)
        return a
now = 0
for i in range(n):
    if ls[i] == i+1:
        now += 1
    else:
        if now != 0:
            di.append(now)
            now = 0
if now != 0:
    di.append(now)
for j in di:
    ans += culc(j)
print(ans)
