#define _CRT_SECURE_NO_WARNINGS #include #include #include //sort #include using namespace std; int main() { int L, N; vector vc; int t; int ans = 0; scanf("%d", &L); scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d", &t); vc.push_back(t); } sort(vc.begin(), vc.end()); for (int i = 0; i < N; i++) { L -= vc.front(); if (L <= 0) break; vc.erase(vc.begin()); ans++; } printf("%d", ans); //system("PAUSE"); return 0; }