N = gets.to_i P = gets.split.map(&:to_i).map(&:pred) indices = [0] * N N.times do |i| indices[P[i]] = i end ans = 0 N.times do |x| if indices[x] > x ans += 1 y = P[x] indices[x], indices[y] = indices[y], indices[x] P[indices[y]] = y end end puts ans