#include #include using namespace std; int L, N, A[10010]; int main() { scanf ("%d %d", &L, &N); for (int i = 0; i < N; i++) scanf ("%d", &A[i]); sort(A, A + N); int c = 0; while (c < N && A[c] <= L) L -= A[c++]; printf ("%d\n", c); return 0; }