package yukicoder; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class N5 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int l = sc.nextInt(); int n = sc.nextInt(); int c = 0; ArrayList blocks = new ArrayList(); for(int i = 0;i < n;++i){ blocks.add(sc.nextInt()); } Collections.sort(blocks); for(int b:blocks){ l -= b; if(l < 0){ System.out.println(c); return; } ++c; } System.out.println(c); } }