#include using namespace std; int l, n; void sort(int* a) { int t; int i, f = 1; while (f && n >= 0) { f = 0; for (i = 0; i < n-1; i++) { if (a[i] > a[i+1]) { a[i] ^= a[i+1]; a[i+1] ^= a[i]; a[i] ^= a[i+1]; f = 1; } } } } int main() { cin >> l >> n; int w[n]; int i; for (i = 0; i < n; i++) cin >> w[i]; sort(w); // 小さい順(昇順) for (i = 0; l >= 0; i++) l -= w[i]; if (l = 0) cout << i << endl; else cout << i-1 << endl; return 0; }