import java.math.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n= sc.nextInt(); int[] omo = new int[n]; for(int i=0;i=0;i--){ for(int j=m-1;j>=0;j--){ if(omo[i]<=hako[j]){ hako[j]-=omo[i]; use[j]=true; break; }else{ if(j==-1){ System.out.println(-1); } continue; } } } int ans=0; for(int i=0;i