import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.Scanner; public class Main { final static Integer DEL_VALUE = new Integer(99); public static void main(String[] args) { try (Scanner scan = new Scanner(System.in)) { int n = Integer.parseInt(scan.next()); ArrayList a = new ArrayList<>(); for(int i=0; i b = new ArrayList<>(); for(int i=0; i > checkList = new LinkedList<>(); LinkedList< ArrayList > nextCheckList = new LinkedList<>(); checkList.add(a); for(int i=0; i nowList = checkList.poll(); ArrayList p = getPermutationList(b.get(i), nowList); for(String flag : p) { ArrayList tmpList = (ArrayList)nowList.clone(); for(int j=0; j= 0 ) { tmpList.remove(DEL_VALUE); } if(tmpList.size() == 0) { System.out.println(i+1); System.exit(0); } nextCheckList.add(tmpList); } } checkList = (LinkedList< ArrayList >)nextCheckList.clone(); nextCheckList.clear(); } System.out.println(-1); } } static ArrayList getPermutationList(final int BOX_SIZE, ArrayList a) { ArrayList pList = new ArrayList<>(); int n = (int)Math.pow(2, a.size()); for(int i=n-1; i>=0; i--) { String flag = Integer.toBinaryString(i); int len = (a.size()-flag.length()); for(int j=0; j BOX_SIZE) break; } } if(sum <= BOX_SIZE) { pList.add(flag); if(pList.size() >= 5) break; } } return pList; } }