#include using namespace std; template inline istream& operator>>(istream &s, vector &v) { for (T &t : v) s >> t; return s; } template inline ostream& operator<<(ostream &s, const vector &v) { for (T &t : v) s << t << endl; return s; } template void sort(vector& v) { sort(v.begin(), v.end()); } template void rsort(vector& v) { sort(v.rbegin(), v.rend()); } template void reverse(vector& v) { reverse(v.begin(), v.end()); } template void unique(vector& v) { v.erase(unique(v.begin(), v.end()), v.end()); } template bool next_permutation(vector& v) { return next_permutation(v.begin(), v.end()); } template int lower_bound(vector& v, T t) { return lower_bound(v.begin(), v.end(), t) - v.begin(); } template void partial_sum(vector& v, vector& u) { partial_sum(v.begin(), v.end(), u.begin()); } int main() { int l, n; cin >> l >> n; vector w(n), v(n); cin >> w; sort(w); partial_sum(w, v); cout << lower_bound(v, l) << endl; }