import java.util.Scanner; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int L = scan.nextInt(); int N = scan.nextInt(); if (L < 1||L > 10000||N < 1||N > 10000) System.exit(1); int[] W = new int[N]; for (int i = 0; i < N; i++) { W[i] = scan.nextInt(); if (W[i] < 1||W[i] > L) System.exit(1); } for (int i = N; i > 1; i--) { heapSort(i, W); swap(W, 0, i-1); } int blocks = 0; for (int i = 0; i < N; i++) { L -= W[i]; if (L < 0) break; blocks++; } System.out.println(blocks); } public static void heapSort (int leaf, int[] A) { int root = leaf/2-1; int tmp; for (int i = root; i >= 0; i--) { while ((root+1)*2 <= leaf) { if ((root+1)*2 == leaf) { tmp = (root+1)*2 - 1; } else { if (A[(root+1)*2 - 1] < A[(root+1)*2]) tmp = (root+1)*2; else tmp = (root+1)*2 - 1; } if (A[root] < A[tmp]) { swap(A, root, tmp); root = tmp; } else break; } root = i - 1; } } public static void swap (int[] A, int a, int b){ int tmp; tmp = A[a]; A[a] = A[b]; A[b] = tmp; } }