#include #include int asc(const void* a, const void* b) { return *(int*)a - *(int*)b; } int main() { int l, n; scanf("%d%d", &l, &n); int i; int w[10004]; for (i = 0; i < n; i++) scanf("%d", &w[i]); qsort(w, n, sizeof(int), asc); int ans = 0; i = 0; while (l - w[i] >= 0) { ans++; l -= w[i]; i++; } printf("%d\n", ans); return 0; }