#include #include #define DEBUG int compare_int(const void *a, const void *b){ return *(int*)a - *(int*)b; } int main(void){ int l, n; scanf("%d%d", &l, &n); int w[10005]; for(int i = 0; i < n; i++){ scanf("%d", w+i); } qsort(w, n, sizeof(int), compare_int); /* int flag = 1; while(flag > 0){ flag = 0; for(int i = 0; i < n-1; i++){ if(w[i] > w[i+1]){ int temp = w[i]; w[i] = w[i+1]; w[i+1] = temp; flag++; } } } */ int sum; for(int i = 0; i < n; i++){ sum += w[i]; if(sum > l){ printf("%d\n", i); break; } } return 0; }