#include #include #include using namespace std; int L; int N; vector W; int solve(int i, int l, int cnt) { if (l > L) return cnt - 1; if (i >= N || l == L) return cnt; int a1 = solve(i+1, l, cnt); int a2 = solve(i+1, l+W[i], cnt+1); return max(a1, a2); } int main() { cin >> L; cin >> N; W.resize(N); for (int n = 0; n < N; n++) { cin >> W[n]; } printf("%d\n", solve(0, 0, 0)); }