#include #include #include #include using namespace std; int L; int N; vector W; int solve(int n, int l, int cnt) { if (l > L) return cnt - 1; if (n >= N || l == L) return cnt; return solve(n+1, l+W[n], cnt+1); } int main() { cin >> L; cin >> N; W.resize(N); for (int n = 0; n < N; n++) { cin >> W[n]; } sort(W.begin(), W.end()); cout << solve(0, 0, 0) << endl; }