/* * 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. */ import java.io.*; import java.io.BufferedReader; import java.io.InputStreamReader; /** * * @author cteam056 */ // předělat na Main class Main { public static BufferedReader in; private static String line; private static int[] monsters; private static String [] strMonsters; private static int N; /** * @param args the command line arguments * @throws java.io.IOException */ public static void main(String[] args) throws IOException { // TODO code application logic here in = new BufferedReader(new InputStreamReader(System.in)); while((line = in.readLine()) != null && !line.isEmpty()) { N = Integer.parseInt(line); monsters = new int[N]; line = in.readLine(); strMonsters = line.split(" "); for(int i = 0; i < N; i++) { monsters[i] = Integer.parseInt(strMonsters[i]); } System.out.println(seradMonstra()); } } private static int seradMonstra() { int retVal = 0; int tmp; for(int i = 0; i < N; i++) { if (monsters[i] != i + 1) { tmp = monsters[i]; monsters[i] = monsters[tmp - 1]; monsters[tmp - 1] = tmp; retVal++; i--; } } return retVal; } }