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(); List blocksLength = new ArrayList<>(); int sumW = 0; for (int i = 0; i <= n; i++) { blocksLength.add(scan.nextInt()); } Collections.sort(blocksLength); for (int i = 0; i <= n; i++) { if (sumW + blocksLength.get(i) <= l) { sumW += blocksLength.get(i); } else { System.out.print(i); break; } } } }