#include #include #define MAX_N 10000 using namespace std; int L, N, W[MAX_N]; int main() { cin >> L >> N; for (int i = 0; i < N; i++) cin >> W[i]; sort(W, W + N); int a = 0; int ttl = 0; for (int i = 0; i < N; i++) { ttl += W[i]; if (ttl > L) break; a++; } cout << a << endl; return 0; }