import sys
from copy import deepcopy
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    P = [0] + list(map(int, input().split()))
    same = deque()
    for i in range(1, N + 1):
        if i == P[i]: same.append(i)
    if not same:
        print(0)
        return
    same2 = deepcopy(same)
    same2.reverse()

    ans = 0
    x = same.popleft()
    while same:
        y = same.popleft()
        ans += y - x
        if same:
            x = same.popleft()
            if not same:
                ans += 1
                break

    ans2 = 0
    x = same2.popleft()
    while same2:
        y = same2.popleft()
        ans2 += x - y
        if same2:
            x = same2.popleft()
            if not same2:
                ans2 += 1
                break
    print(min(ans, ans2))

if __name__ == "__main__":
    main()
