#include #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ int a, n; cin >> a >> n; vector w(n); rep(i, n)cin >> w[i]; int cnt = 0; rep(i, n){ sort(w.begin(), w.end()); a -= w[i]; if(a < 0) break; cnt++; } cout << cnt << endl; return 0; }