#include #define int long long #define double long double using namespace std; const int MOD = 1000000007; const int INF = 1e14; using Graph = vector>; signed main(){ int L, N; cin >> L >> N; vector W(N); for( int i = 0; i < N; i++ ) cin >> W[i]; sort(W.begin(), W.end()); int now = 0; for( int i = 0; i < N; i++ ){ if( now+W[i] > L ){ cout << i << endl; return 0; } now += W[i]; } cout << N << endl; }