#include #include #include using namespace std; int main(){ // input int L,N; cin >>L >> N; unsigned long long W[N+1]={}; W[0] = 0; unsigned long long sum[N+1]={}; sum[0] = 0; for(int i=1;i<=N;i++){ cin >> W[i]; /// cout << W[i] << "," << i << endl; } sort(W,W+N+1); int ans=0; for(int i=1;i<=N;i++){ sum[i] += sum[i-1] + W[i]; } for(int i=0;i<=N;i++){ // cout << sum[i] << "," << i << endl; if(sum[i] > L){ ans = i-1; break; } } /* int Left=0,Right=N; while(Left<=Right){ int center = (Left+Right)/2; if(sum[Right] < L){ Left = center + 1; } else if (sum[Left] > L){ if(sum[Left-1] <= L){ ans = Left -1; break; } } } */ cout << ans << endl; // output }