#include using namespace std; typedef long long ll; int main() { ll L; ll N; cin >> L; cin >> N; ll W[N + 1]; for (ll i = 0; i < N; i++) { cin >> W[i]; } sort(W, W + N); ll i = 0; while (L >= 0) { L -= W[i]; i++; } cout << i-1 << endl; }