import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; class sampleA { public static void main(String args[]) { Scanner scan = new Scanner(System.in); int l = scan.nextInt(); int n = scan.nextInt(); int answer = 0; List blocksLength = new ArrayList<>(); int sumW = 0; for (int i = 0; i < n; i++) { blocksLength.add(scan.nextInt()); } scan.close(); Collections.sort(blocksLength); for (int w : blocksLength) { if (sumW + w <= l) { sumW += w; answer++; } else { System.out.print(answer); break; } } } }