import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); int l = Integer.parseInt(line); line = br.readLine(); int n = Integer.parseInt(line); line = br.readLine(); String[] lines = line.split(" "); Arrays.sort(lines); int total = 0; int res = 0; for (int t = 0; t < n; t++) { int v = Integer.parseInt(lines[t]); if ((total + v) > l) { break; } total += v; res++; } System.out.println(res); } }