import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String... args) { int L, N; var sin = new Scanner(System.in); L = Integer.parseInt(sin.nextLine()); N = Integer.parseInt(sin.nextLine()); String[] W = sin.nextLine().split(" "); int[] some = new int[W.length]; Arrays.setAll(some, i -> Integer.parseInt(W[i])); Arrays.sort(some); int sum = 0, i; for (i = 0; i < N; i++) { sum += some[i]; if (sum > L) break; } System.out.println(i); } }