import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int L = Integer.parseInt(reader.readLine()); int N = Integer.parseInt(reader.readLine()); String[] line = reader.readLine().split(" "); int[] blocks = new int[N + 1]; for (int i = 0; i < N; i++) { blocks[i + 1] = Integer.parseInt(line[i]); } Arrays.sort(blocks); int counter = 0; for (int i = 1; i <= N; i++) { blocks[i] = blocks[i - 1] + blocks[i]; if (blocks[i] > L) { break; } else { counter += 1; } } System.out.println(counter); } }