import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam014 */ public class Monsters { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); public void solve() throws Exception { String line; while ((line = reader.readLine()) != null) { int N = Integer.parseInt(line); int count = 0; int[] rooms = new int[N+1]; line = reader.readLine(); String[] a = line.split(" "); for (int i = 0; i < a.length; i++) { rooms[i+1] = Integer.parseInt(a[i]); } boolean change = true; while(change){ change = false; for (int i = 1; i < rooms.length; i++) { if(rooms[i] != i){ int temp = rooms[i]; int temp2 = rooms[temp]; rooms[temp] = temp; rooms[i] = temp2; count++; change = true; } } } System.out.println(count); } } public static void main(String[] args) throws Exception { new Monsters().solve(); } }