/* * 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. */ package monsters; import java.util.Scanner; /** * * @author cteam057 */ public class Monsters { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner sc = new Scanner(System.in); int chambers = sc.nextInt(); int[] monsters = new int[chambers]; int episodes = 0; int smallest = 1; for (int i = 0; i < chambers; i++) { monsters[i] = sc.nextInt(); } for (int i = 0; i < chambers; i++) { int k = i; while (monsters[k] != smallest) { k++; } if (monsters[k] != monsters[i]) { int buffer = monsters[i]; monsters[i] = monsters[k]; monsters[k] = buffer; episodes++; //smallest++; } smallest++; } System.out.print(episodes); } }