package yukicoder; import java.util.Scanner; public class No5v2 { 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; int CL = L; int k = 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; } while(CL >0 && CL - w[k] > 0){ CL -= w[k]; k++; c++; } System.out.println(c); sc.close(); } }