# -*- coding: utf-8 -*-


def main():
    n = int(input())
    p = list(map(int, input().split()))
    zeros = list()
    ans = 0

    for index, pi in enumerate(p, 1):
        diff = pi - index

        if diff == 0:
            zeros.append(pi)

    zero_count = len(zeros)

    if zero_count % 2 == 0:
        for i in range(zero_count // 2):
            ans += zeros[2 * i + 1] - zeros[2 * i]
    else:
        candidate1 = zeros[1:]
        candidate2 = zeros[:-1]
        ans1 = 0
        ans2 = 0

        for z1 in range(zero_count // 2):
            ans1 += candidate1[2 * z1 + 1] - candidate1[2 * z1]

        for z2 in range(zero_count // 2):
            ans2 += candidate2[2 * z2 + 1] - candidate2[2 * z2]

        ans = min(ans1, ans2) + 1

    print(ans)


if __name__ == '__main__':
    main()
