package yukicoder; import java.util.Scanner; public class No5 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int L = sc.nextInt(); int N = sc.nextInt(); int[] w = new int[N]; int tmp = 0; int c = 0; for(int i = 0; i < w.length; i++){ w[i] = sc.nextInt(); } for(int j = 1; j < w.length; j++){ int tmp2 = w[j]; int i = j - 1; while(i >= 0 && w[i] > tmp2){ w[i + 1] = w[i]; i--; } w[i + 1] = tmp2; } for(int i = 0; i < w.length; i++){ if(L - tmp >= w[i]){ tmp += w[i]; c++; }else{ break; } } System.out.println(c); sc.close(); } }