package yukicoder; import java.util.Arrays; import java.util.Scanner; public class No5v2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int L = sc.nextInt(); int N = sc.nextInt(); int[] w = new int[N]; int tmp = 0; int c = 0; for (int i = 0; i < w.length; i++) { w[i] = sc.nextInt(); } sc.close(); Arrays.sort(w);//ソート for (int n : w) { if (L - tmp >= n) { tmp += n; c++; } else { break; } } System.out.println(c); } }