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(" "); int[] ws = new int[n]; for (int t = 0; t < n; t++) { ws[t] = Integer.parseInt(lines[t]); } Arrays.sort(ws); int total = 0; int res = 0; for (int w : ws) { if ((total + w) > l) { break; } total += w; res++; } System.out.println(res); } }