#include #include #include using namespace std; int main() { int sum; cin >> sum; long int blocks[10000]; int kara[1]; int n; cin >> n; int ans=0; for (int i = 0; i <= n - 1; i++) { blocks[i] = 0; cin >> blocks[i]; } for (int k = 0; k <= n - 1; k++) { for (int j = k; j <= n - 1; j++) { if (blocks[j] < blocks[k]) { kara[0] = blocks[k]; blocks[k] = blocks[j]; blocks[j] = kara[0]; } } } for (int s = 0; s <= n - 1; s++) { ans = ans + blocks[s]; if (ans > sum) { cout << s; break; } else if (s == n - 1) { cout << s + 1; } } }