import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.math.*; public class Main { public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int l = Integer.parseInt(br.readLine()); int n = Integer.parseInt(br.readLine()); String[] str = br.readLine().split(" "); int[] w = new int[n]; for(int i = 0; i < n; i++){ w[i] = Integer.parseInt(str[i]); } Arrays.sort(w); int sum = 0; for(int i = 0; i < n; i++){ sum += w[i]; if(sum>l){ sb.append(i); System.out.println(sb); return; } } sb.append(n); System.out.println(sb); } }