import java.util.Scanner; public class Main { 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]; for (int i = 0; i < w.length; i++) { w[i] = sc.nextInt(); } int h = w.length; while (h >= 1) { h >>= 1; for (int i = 0; i < w.length - h; i++) { if (w[i] > w[i + h]) { int tmp = w[i]; w[i] = w[i + h]; w[i + h] = tmp; } } } int i = 0; for (; i < w.length; i++) { l -= w[i]; if (l < 0) { break; } } System.out.println(i); } }