import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int L = Integer.parseInt(br.readLine()); int N = Integer.parseInt(br.readLine()); String[] input = br.readLine().split(" "); int[] W = new int[N]; for(int i = 0; i < N; i++) W[i] = Integer.parseInt(input[i]); for(int i = 0; i < N - 1; i++) { for(int j = i + 1; j < N; j++) { if(W[i] > W[j]) { int x = W[i]; W[i] = W[j]; W[j] = x; } } } int sum = 0; int count = 0; for(int i = 0; i < N; i++) { if(sum + W[i] <= L) { sum += W[i]; count++; } } System.out.println(count); } }