CodeEff/ECCO huggingface dataset:
# Original solution
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    P = LIST()

    P.append(-1)
    cnt = 0
    i = 0
    while i < N:
        if P[i] == i + 1:
            cnt += 1
            i += (P[i+1] == i + 2)
        i += 1

    print(cnt)


if __name__ == '__main__':
    main()


# Optimized solution
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    P = LIST()

    P.append(-1)
    cnt = 0
    for i in range(N):
        if P[i] == i + 1:
            cnt += 1
            P[i+1] = P[i]

    print(cnt)


if __name__ == '__main__':
    main()
# Original solution
n=int(eval(input()))
arr=list(map(int,input().split()))
ans=0
for i in range(n-2):
  if arr[i]==i+1:
    arr[i],arr[i+1]=arr[i+1],arr[i]
    ans+=1
  elif arr[i+1]==i+1:
    arr[i+1],arr[i+2]=arr[i+2],arr[i+1]
if arr[-1]==n or arr[-2]==n-1:
  ans+=1
print(ans)


# Optimized solution
n=int(eval(input()))
arr=list(map(int,input().split()))
ans=0
for i in range(n-1,-1,-1):
  if arr[i]==i+1:
    arr[i],arr[i-1]=arr[i-1],arr[i]
    ans+=1
print(ans)
# Original solution
N = int(eval(input()))
p = list(map(int,input().split()))
import queue
from math import ceil
que = queue.Queue()
ans = 0
for i in range(N):
    if p[i]==i+1:
        que.put(i)
    else:
        ans+=ceil(que.qsize()/2)
        que = queue.Queue()
ans+=ceil(que.qsize()/2)
print(ans)

# Optimized solution
N = int(eval(input()))
p = list(map(int,input().split()))

ans = 0
i = 0
while i < N:
    if p[i] == i+1:
        ans += 1
        if i+1 < N and p[i+1]==i+2:
            i += 1
    i += 1
print(ans)
# Original solution
n = int(eval(input()))
p = list(map(int, input().split()))

cnt = 0
increased = False
for i in range(n):
    if increased:
        increased = False
        continue

    if p[i] == i+1:
        cnt += 1
        i += 1
        increased = True

print(cnt)

# Optimized solution
n = int(eval(input()))
p = list(map(int, input().split()))

cnt = 0
increased = False

for i in range(n):
    if increased:
        increased = False

    elif p[i] == i+1:
        cnt += 1
        increased = True

print(cnt)
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))
l = [x-1 for x in l]

ans = 0
for i in range(n):
  if l[i] == i:
    ans += 1
    if i != n-1:
      l[i+1] = l[i]
print(ans)
    

# Optimized solution
n = int(eval(input()))
P = list(map(int, input().split()))

P = [p-1 for p in P]
ans = 0
for i in range(n):
    if P[i] == i:
        if i != n-1:
            ans += 1
            P[i+1] = P[i]
        else:
            ans += 1
print(ans)
# Original solution
n = int(eval(input()))
P = list(map(int, input().split()))

P = [p-1 for p in P]
ans = 0
for i in range(n):
    if P[i] == i:
        if i != n-1:
            ans += 1
            P[i+1] = P[i]
        else:
            ans += 1
print(ans)


# Optimized solution
n = int(eval(input()))
P = list(map(int, input().split()))
P = [p-1 for p in P]

ans = 0
for i in range(n):
    if i != n-1:
        if P[i] == i:
            ans += 1
            P[i+1] = P[i]
    else:
        if P[i] == i:
            ans += 1
print(ans)
# Original solution
N=int(eval(input()))
alist=[0]+list(map(int,input().split()))

answer=0
if alist[N]==N:
  alist[N-1],alist[N]=alist[N],alist[N-1]
  answer+=1

for i in range(1,N+1):
  if alist[i]==i:
    alist[i],alist[i+1]=alist[i+1],alist[i]
    answer+=1
    
print(answer)

# Optimized solution
N=int(eval(input()))
alist=[0]+list(map(int,input().split()))

answer=0
for i in range(1,N):
  if alist[i]==i:
    alist[i],alist[i+1]=alist[i+1],alist[i]
    answer+=1
    
if alist[N]==N:
  print((answer+1))
else:
  print(answer)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
for i in range(n):
    a[i]-=1
ans=0
for i in range(n-1):
    if a[i]==i and a[i+1]==i+1:
        ans+=1
        a[i],a[i+1]=i+1,i
    if a[i]==i:
        ans+=1
if a[-1]==n-1:
    ans+=1
print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
    if a[i]==i+1:
        a[i],a[i+1]=a[i+1],a[i]
        ans+=1
if a[-1]==n:
    ans+=1
print(ans)
# Original solution
N = int(eval(input()))
p = [int(x) for x in input().split()]

ans = 0
for i in range(N):
  if i < N - 1 and p[i] == i + 1:
    p[i] = p[i+1]
    p[i+1] = i+1
    ans += 1
  elif i == N -1 and p[i] == i+1:
    p[i] = p[i-1]
    p[i-1] = i + 1
    ans += 1
print(ans)

# Optimized solution
N = int(eval(input()))
p = list(map(int, input().split()))
ans = 0
for i in range(N):
    if p[i]-1 == i:
        if i + 1 <= N-1:
            p[i] = p[i+1]
            p[i+1] = i + 1
            ans += 1
        elif i - 1 >= 0:
            p[i] = p[i-1]
            p[i-1] = i + 1
            ans += 1
print(ans)
# Original solution
n = int(eval(input()))
p = [int(i) for i in input().split()]
i = 0
ans = 0
while i < n:
    if i < n - 1:
        if p[i] == i + 1:
            p[i], p[i+1] = p[i+1], p[i]
            ans += 1
    elif p[i] == i + 1:
        ans += 1
    i += 1
print(ans)


# Optimized solution
n = int(eval(input()))
p = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    if i < n - 1:
        if p[i] == i + 1:
            p[i], p[i+1] = p[i+1], p[i]
            ans += 1
    elif p[i] == i + 1:
        ans += 1
print(ans)
# Original solution
N = int(eval(input()))
P = list(map(int, input().split()))
count = 0
while True:
    for i in range(N-1):
        if i + 1 == P[i]:
            P[i], P[i+1] = P[i+1], P[i]
            count += 1
    flag = True
    for i in range(1, N+1):
        if i == P[i-1]:
            flag = False
            break
    if flag:
        break

print(count)

# Optimized solution
N = int(eval(input()))
P = list(map(int, input().split()))
count = 0
for i in range(N-1):
    if i + 1 == P[i]:
        P[i], P[i+1] = P[i+1], P[i]
        count += 1

if N == P[N-1]:
    count += 1
print(count)
# Original solution
N = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
if p[0] == 1:
    tmp = p[1]
    p[1] = p[0]
    p[0] = tmp
    cnt += 1

for i in range(N - 1, -1, -1):
    if i + 1 == p[i]:
        tmp = p[i]
        p[i] = p[i - 1]
        p[i - 1] = tmp
        cnt += 1

print(cnt)

# Optimized solution
N = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
#if p[0] == 1:
#    tmp = p[1]
#    p[1] = p[0]
#   p[0] = tmp
#    cnt += 1

for i in range(N - 1, -1, -1):
    if i + 1 == p[i]:
        tmp = p[i]
        p[i] = p[i - 1]
        p[i - 1] = tmp
        cnt += 1

print(cnt)
# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, p: "List[int]"):

    ans = 0
    
    for i in range(N-1):
        
        if(i+1 == p[i]):
            p[i],p[i+1] = p[i+1],p[i]
            ans += 1

    for i in range(N-1,-1,-1):
        if(i+1 == p[i]):
            p[i],p[i-1] = p[i-1],p[i]
            ans += 1    

    print(ans)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, p: "List[int]"):

    ans = 0
    
    for i in range(N-1):
        if(i+1 == p[i]):
            p[i],p[i+1] = p[i+1],p[i]
            ans += 1

    if(N == p[N-1]):
        ans += 1

    print(ans)

    # for i in range(N-1):
        
    #     if(i+1 == p[i]):
    #         p[i],p[i+1] = p[i+1],p[i]
    #         ans += 1

    # for i in range(N-1,-1,-1):
    #     if(i+1 == p[i]):
    #         p[i],p[i-1] = p[i-1],p[i]
    #         ans += 1    

    # print(ans)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
P = list([int(a) - 1 for a in input().split()])

ans = 0
for i in range(N):
    p = P[i]
    if p == i:
        if i < N - 1:
            P[i], P[i + 1] = P[i + 1], P[i]
        ans += 1

print(ans)

# Optimized solution
N = int(eval(input()))
P = list(map(int, input().split()))

ans = 0

for i in range(N):
    if P[i] == i + 1:
        if i + 1 < N:
            P[i], P[i + 1] = P[i + 1], P[i]
        ans += 1
print(ans)
# Original solution
n = int(eval(input()))
p = list(map(int,input().split()))

cnt = 0
tmp = [-1,-1]
for i in range(n):
  if p[i] == i+1:
    if i+1 == tmp[0]+1 and p[i]==tmp[1]+1:
      cnt+=0
      tmp = [-1, -1]      
    else:
      cnt+=1
      tmp = [i+1,p[i]]
#    print(p[i],tmp,cnt)
print(cnt)

# Optimized solution
n = int(eval(input()))
p = list(map(int,input().split()))

cnt = 0
tmp = -1
for i in range(n):
  if p[i] == i+1:
    if i+1 == tmp+1:
      cnt+=0
      tmp = -1     
    else:
      cnt+=1
      tmp = i+1
print(cnt)
# Original solution
N = int(eval(input()))
p = tuple(map(int, input().split()))
a = list(p)
b = list(p)

c = 0
for i in range(N):
    if i+1 == a[i] and i == N-1:
        c += 1
    elif i+1 == a[i]:
        a[i], a[i+1] = a[i+1], a[i]
        c += 1
cc = 0        
for i in range(N)[::-1]:
    if i+1 == b[i] and i == 0:
        cc += 1
    if i+1 == b[i]:
        b[i], b[i-1] = b[i-1], b[i]
        cc += 1
        
print((min(c,cc)))

# Optimized solution
N = int(eval(input()))
p = tuple(map(int, input().split()))
a = list(p)
b = list(p)

c = 0
for i in range(N):
    if i+1 == a[i] and i == N-1:
        c += 1
    elif i+1 == a[i]:
        a[i], a[i+1] = a[i+1], a[i]
        c += 1
cc = 0        
for i in range(N)[::-1]:
    if i+1 == b[i] and i == 0:
        cc += 1
    elif i+1 == b[i]:
        b[i], b[i-1] = b[i-1], b[i]
        cc += 1
        
print((min(c,cc)))
# Original solution
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(eval(input()))
    p_list = list(map(int, input().split()))
    a_list = list(range(1, N + 1))
    ans = 0
    i = 0
    while i < N:
        if i + 1 < N and p_list[i] == a_list[i] and p_list[i + 1] == a_list[i + 1]:
            ans += 1
            i += 2
        elif p_list[i] == a_list[i]:
            ans += 1
            i += 2
        else:
            i += 1
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(eval(input()))
    p_list = list(map(int, input().split()))
    ans = 0
    i = 0
    while i < N:
        if p_list[i] == i + 1:
            ans += 1
            i += 2
        else:
            i += 1
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
p = list(map(int, input().split()))
temp = []

for i in range(n):
    # print(i, p[i])
    if p[i] == i+1:
        temp.append('y')
        continue

    # if p[i] == i+1:
    #     if p[i-1] == i:
    #         del temp[-1]
    #         temp.append('x')
    #     else:
    #         temp.append('y')
    #     continue

    temp.append(p[i])

idx = 1
while True:
    if idx > len(temp) - 1:
        break

    if temp[idx] == 'y' and temp[idx-1] == 'y':
        temp[idx-1] = 'x'
        del temp[idx]
        # del temp[idx-1]
        # temp.append('x')

    idx += 1


#print(temp)
ans = temp.count('x') + temp.count('y')
print(ans)

# Optimized solution
n = int(eval(input()))
p = list(map(int, input().split()))
temp = []

for i in range(n):
    # print(i, p[i])
    if p[i] == i+1:
        temp.append('y')
        continue

    temp.append(p[i])

a = []

idx = 1
while True:
    if idx > len(temp) - 1:
        break

    if temp[idx] == 'y' and temp[idx-1] == 'y':
        temp[idx-1] = 'x'
        temp[idx] = 'x'
        #del temp[idx]
        # del temp[idx-1]
        # temp.append('x')

    idx += 1


#print(a)
ans = temp.count('x')//2 + temp.count('y')
print(ans)


'''
9
1 2 4 9 5 8 7 3 6
'''
# Original solution
import sys

def solve():
    input = sys.stdin.readline
    N = int(eval(input()))
    P = [int(p) for p in input().split()]
    count = 0
    now = 0
    while now < N:
        if P[now] == now + 1:
            count += 1
            if now < N - 1:
                if P[now + 1] == now + 2: now += 1
        now += 1
    print(count)
   

    return 0

if __name__ == "__main__":
    solve()

# Optimized solution
import sys

def solve():
    input = sys.stdin.readline
    N = int(eval(input()))
    P = [int(p) for p in input().split()]
    swap = 0
    for i in range(N):
        if P[i] == i + 1:
            if i < N - 1: P[i], P[i+1] = P[i+1], P[i]
            swap += 1
    print(swap)
    return 0

if __name__ == "__main__":
    solve()
# Original solution
# ABC 072 D
N = int(eval(input()))
p = list(map(int,input().split()))
ans = 0

r = [0 for k in range(N)]
for k in range(N):
    if p[k] == k+1:
        r[k] = 1
for k in range(1,N):
    if r[k] > 0:
        r[k] += r[k-1]

r = r + [0]

for k in range(1,N+1):
    if r[k] == 0:
        ans += (r[k-1]+1)//2

print(ans)


# Optimized solution
N = int(eval(input()))
p = list(map(int,input().split()))
l = [0 for k in range(N+2)]

for k in range(N):
    if p[k] == k+1:
        l[k+1] = 1

t = 0
ans = 0
for e in l:
    if e == 1:
        t += 1
    else:
        ans += (t+1)//2
        t = 0
print(ans)
# Original solution
N=int(eval(input()))
P=list(map(int,input().split()))
S=[]
for x,y in zip(P, list(range(1,N+1))):
    if x==y: S.append(y)

S.append('$')
L=len(S)

lake=[]
lake.append(S[0])
i=1
a=0
while i<L:
    if S[i]=='$':
     a+=1
    elif lake[0]+1!=S[i]:
     a+=1
     lake=[]
     lake.append(S[i])
    else:
     lake.append(S[i])
    i+=1
print(a)

# Optimized solution
N=int(eval(input()))
S=[]
for x,y in zip(list(map(int,input().split())), list(range(1,N+1))):
 if x==y: S.append(y)

S.append('$')
L=len(S)

l=[S[0]]
i=1
a=0
while i<L:
  if S[i]=='$':a+=1
  elif l[0]+1!=S[i]:
     a+=1
     l=[S[i]]
  else:l.append(S[i])
  i+=1
print(a)
# Original solution
N = int(eval(input()))
P = list(map(int, input().split()))
c = 0
for i in range(N):
    if P[i] == i+1:
        if i != N - 1:
            t = P[i]
            P[i] = P[i+1]
            P[i+1] = t
            c += 1
        else:
            t = P[i]
            P[i] = P[i-1]
            P[i-1] = t
            c += 1
print(c)

# Optimized solution
N = int(eval(input()))
P = list(map(int, input().split()))
c = 0
for i in range(N):
    f = 1
    if P[i] == i+1:
        if i != N - 1:
            if P[i+1] != i+1:
                t = P[i]
                P[i] = P[i+1]
                P[i+1] = t
                c += 1
        else:
            if P[i-1] != i+1:
                t = P[i]
                P[i] = P[i-1]
                P[i-1] = t
                c += 1
print(c)
# Original solution
import itertools
def solve():
    N = int(eval(input()))
    p = list(map(int, input().split()))
    chk = ""

    for i in range(N):
        if p[i] == i + 1:
            chk += "1"
        else:
            chk += "0"
    
    chk_splited = chk.split('0')

    cnt = 0
    for c in chk_splited:
        if len(c) % 2 == 0:
            cnt += len(c) / 2
        else:
            cnt += len(c) //2 + 1
    print((int(cnt)))

if __name__ == '__main__':
    solve()


# Optimized solution
import itertools
def solve():
    N = int(eval(input()))
    p = list(map(int, input().split()))

    one_cnt = 0
    swap_cnt = 0
    for i in range(N):
        if p[i] == i + 1:
            one_cnt += 1
        else:
            if one_cnt % 2 == 0:
                swap_cnt += one_cnt / 2
            else:
                swap_cnt += one_cnt // 2 + 1
            one_cnt = 0
    
    else:
        if one_cnt % 2 == 0:
            swap_cnt += one_cnt / 2
        else:
            swap_cnt += one_cnt // 2 + 1

    print((int(swap_cnt)))

if __name__ == '__main__':
    solve()
# Original solution
def check(n,p):
    for i in range(n):
        if (i+1) == p[i]:
            return False
    return True

def solve(n,p):
    
    memo = {}
    items = [(0,p)]
    result = 0
    while items:
        step, p = items.pop(0)
        if check(n,p):
            result = step
            break
        else:
            for i in range(n-1):
                candidate = tuple( p[:i] +[ p[i+1] ,p[i]] + p[i+2:] )
                if not candidate in memo:
                    items.append([step +1 , list(candidate)])
                    memo[candidate] = step + 1
                
    return result

if __name__ == '__main__':
    n = int(eval(input()))
    p = list(map(int, input().split(" ")))
    print((solve(n, p)))


# Optimized solution
def solve(n, p):
    result = 0
    for i in range(n-1):
        if (i+1) == p[i]:
            p[i], p[i+1] = p[i+1],p[i]
            result += 1
    i = n - 1
    if (i+1) == p[i]:
        p[i-1], p[i] = p[i],p[i-1]
        result += 1
    return result

if __name__ == '__main__':
    n = int(eval(input()))
    p = list(map(int, input().split(" ")))
    print((solve(n, p)))
# Original solution
# sys.stdin.readline()
import sys
input = sys.stdin.readline

n = int(eval(input()))
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if i+1 == p[i]:
        if p[i]+1 == p[i+1]:
            p[i+1] = p[i]
        ans += 1
if p[n-1] == n:
    ans += 1
print(ans)

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *p = list(map(int, read().split()))
p += [0]
cnt = 0
for i, pp in enumerate(p):
    if (i + 1) == pp:
        p[i + 1] = 0
        cnt += 1
print(cnt)
# Original solution
n = int(eval(input()))
cnt = 0
p = list(map(int,input().split()))
for i in range(n):
    if p[i]==i+1:
        if i==0:
            p[i+1],p[i] = p[i],p[i+1]
            cnt+=1
        elif i==n-1:
            cnt+=1
            break
        elif p[i]==i+2:
            p[i-1],p[i] = p[i],p[i-1]
            cnt+=1
        else:
            p[i],p[i+1] = p[i+1],p[i]
            cnt+=1
print(cnt)

# Optimized solution
def solve():
    n = int(eval(input()))
    l = list(map(int,input().split()))
    res = 0
    for i in range(n-1):
        if l[i]==i+1:
            l[i],l[i+1]=l[i+1],l[i]
            res+=1
    if l[n-1]==n:
        res+=1
    print(res)
if __name__=='__main__':
    solve()
# Original solution
N = int(eval(input()))
P = list(map(int,input().split()))

ls = [""] * N
cnt = 0

for i in range(N):
  if P[i] == i + 1:
    ls[i] = "#"
  else:
    ls[i] = "."
    
if ls[-1] == "#":
  if ls[-2] == "#":
    ls[-1], ls[-2] = ".", "."
  else:
    ls[-1] = "."
  cnt += 1

for j in range(N-1):
  if ls[j] == "#":
    if ls[j+1] == "#":
      ls[j+1] = "."
    cnt += 1
    
print(cnt)

# Optimized solution
N = int(eval(input()))
P = list(map(int,input().split()))

ans = 0

if P[-1] == N:
  ans += 1
  P[-1] = -1
  if P[-2] == N - 1:
    P[-2] = -1

for i in range(N-1):
  if P[i] == i + 1:
    ans += 1
    if P[i+1] == i + 2:
      P[i+1] = -1
      
print(ans)
# Original solution
N = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
i = 0
while i < N:
    if i + 1 == p[i]:
        c = 1
        for j in range(i + 1, N):
            if j+1 != p[j]:
                i = j
                break
            else:
                c += 1
        i = j
        cnt += (c+1)//2
    i += 1

print(cnt)
        

# Optimized solution
N = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
i = 0
while i < N:
    if i + 1 == p[i]:
        c = 1
        j = i+1
        while j < N:
            if j+1 != p[j]:
                i = j
                break
            else:
                c += 1
            j += 1
        else:
            i = j
        cnt += (c+1)//2
    i += 1

print(cnt)
# Original solution
N = int(eval(input()))
P = list(map(int, input().split()))

cnt = 0
t = 'o' if P[0] == 1 else 'x'
j = 0 if t == 'o' else 1
L = []
for i, p in enumerate(P):
    s = 'o' if p == (i + 1) else 'x'
    if s == t:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
        t = s
L.append(cnt)

ans = 0
for i, n in enumerate(L):
    if i % 2 == j:
        ans += (n + 2 - 1) // 2

print(ans)


# Optimized solution
N = int(eval(input()))
P = list(map(int, input().split()))

cnt = 0
ans = 0
t = 'o' if P[0] == 1 else 'x'
for i, p in enumerate(P):
    s = 'o' if p == (i + 1) else 'x'
    if s == t:
        cnt += 1
    else:
        if t == 'o':
            ans += (cnt + 2 - 1) // 2
        cnt = 1
        t = s
else:
    if t == 'o':
        ans += (cnt + 2 - 1) // 2

print(ans)
# Original solution
n=int(eval(input()))
p=[int(i) for i in input().split()]
cnt=0
for i in range(n-1):
	if p[i]==i+1:
		p[i],p[i+1]=p[i+1],p[i]
		cnt+=1
if p[-1]==n:cnt+=1
print(cnt)

# Optimized solution
n,*p=list(map(int,open(0).read().split()))
i=c=0
while i<n:
	if p[i]==i+1:
		i+=1
		c+=1
	i+=1
print(c)
# Original solution
N = int(eval(input()))
P = list(map(int,input().split()))
ans = 0

for n in range(N-1):
  if P[n]==n+1 and P[n+1]==n+2:
    ans+=1
    P[n+1] = n+1
  elif P[n]==n+1 and P[n+1]!=n+2:
    ans+=1

if P[-1]==N:
  print((ans+1))
else:
  print(ans)

# Optimized solution
N = int(eval(input()))
P = list(map(int,input().split()))
c = 0

for n in range(N-1):
  if P[n]==n+1:
    P[n],P[n+1] = P[n+1],P[n]
    c+=1

if P[-1]==N:
  print((c+1))
else:
  print(c)
# Original solution
n = int(eval(input()))
p = list(map(int, input().split()))

x = []

for i in range(n):
    if p[i] - 1 == i:
        x.append('x')
    else:
        x.append('o')

cnt = 0
for i in range(n-1):
    if x[i] == "x" and x[i+1] == 'o':
        cnt += 1
    elif x[i] == "x" and x[i+1] == 'x':
        cnt += 1
        x[i+1] = 'o'

if x[n-1] == "x":
    cnt += 1

print(cnt)

# Optimized solution
n = int(eval(input()))
p = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if p[i]-1 == i:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1

if p[-1] == n:
    ans+=1

print(ans)