#include using namespace std; const int INF = 2147483647; const int MOD = 1048576; int main(void) { 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, ans = 0; while (now + W[ans] <= L) { now += W[ans]; ans++; } cout << ans << endl; return 0; }