// No.365 import java.util.Scanner; import java.util.ArrayList; class JengaSort{ public static void main(String[] args){ ArrayList jengaList = new ArrayList<>(); Scanner scan = new Scanner(System.in); int result = 0; int max = scan.nextInt(); for(int i = 0; i < max; i++){ jengaList.add(scan.nextInt()); } for(int i = max - 1; i > 0; i--){ Integer iIndex = jengaList.indexOf(i); Integer nIndex = jengaList.indexOf(i + 1); if(iIndex > nIndex){ // 左にもっていく while(iIndex > 0){ Integer before = jengaList.set(iIndex - 1, i); jengaList.set(iIndex, before); iIndex--; } } result++; } System.out.println(result); } }