import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; public class No5 { public static void main(String args[]){ String str = ""; int boxSize = 0; int blockQuantity = 0; ArrayList blockSize = new ArrayList(); BufferedReader input = new BufferedReader (new InputStreamReader (System.in)); try { str = input.readLine(); boxSize = Integer.parseInt(str); str = input.readLine(); blockQuantity = Integer.parseInt(str); for(int i = 0; i < blockQuantity; i++){ str = input.readLine(); blockSize.add(Integer.parseInt(str)); }; Collections.sort(blockSize); int cnt; for(cnt = 0 ;0 <= boxSize;cnt++){ boxSize = boxSize - blockSize.get(cnt); } System.out.println(cnt - 1); } catch (IOException e) { e.printStackTrace(); } } }