import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class No5 { public static void main(String args[]){ String str = ""; int boxSize = 0; int blockQuantity = 0; ArrayList blockSize = new ArrayList(); Scanner sc = new Scanner(System.in); BufferedReader input = new BufferedReader (new InputStreamReader (System.in)); //str = input.readLine(); boxSize = sc.nextInt(); //str = input.readLine(); blockQuantity = sc.nextInt(); for(int i = 0; i < blockQuantity; i++){ blockSize.add(sc.nextInt()); }; Collections.sort(blockSize); int cnt = 0; while(true){ boxSize = boxSize - blockSize.get(cnt); if(boxSize < 0 || boxSize == 0){ if(boxSize==0) cnt++; break; } cnt++; if(blockQuantity==cnt){break;} } System.out.println(cnt); } }