#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF (INT_MAX/3) #define PI (2*acos(0.0)) #define EPS (1e-8) typedef long long ll; typedef unsigned long long ull; int main(){ ios_base::sync_with_stdio(0); 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 len = 0, cnt = 0; for(int i = 0; i < W.size(); i++){ len += W[i]; if(len > L) break; cnt++; } cout << cnt << endl; return 0; }