#include #include using namespace std; int main(){ int k,n,to=0,q=0; cin >> k >> n; int a[n]; for(int i; i < n; i++) cin >> a[i]; sort(a,n+a); for(int i=0; i < n; i++){ to += a[i]; if(to <= k) q++; else break; } cout << q << endl; return 0; }