class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.rank = [0 for _ in range(n + 1)]
        self.weight = [0 for _ in range(n + 1)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            y = self.find(self.parent[x])
            self.weight[x] += self.weight[self.parent[x]]
            self.parent[x] = y
            return y

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.parent[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.parent[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def check_same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]


N = int(input())
p_list = list(map(int, input().split()))
unionfind = UnionFind(N)
for i in range(N - 1):
    p = p_list[i]
    p2 = p_list[i + 1]
    unionfind.union(p, p2, 1)

diff_list = []
for i in range(N):
    diff_list.append(unionfind.diff(i+1, p_list[i]))

count = 0
for i in range(len(diff_list)-1):
    if diff_list[i] == 0:
        diff_list[i+1] = -1
        count += 1
print(count)

