#include using namespace std; #define all(x) x.begin(),x.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) template inline bool chmax(T&a,T b){if(a inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;} using ll = long long; int l,n,sum,ans; int w[100005]; int main(){ cin >> l >> n; rep(i,n) cin >> w[i]; sort(w,w+n); rep(i,n) if(sum+w[i]<=l) sum+=w[i], ans++; cout << ans << endl; }