#if defined(__GNUG__) && !defined(__clang__) #include #endif #define inf(T) (numeric_limits::min()) #define sup(T) (numeric_limits::max()) #define rep(i,n) for (int i = 0; i < (n); i++) #define asc(c) (c).begin(), (c).end() #define desc(c) (c).rbegin(), (c).rend() #define mp(...) make_pair(__VA_ARGS__) #define mt(...) make_tuple(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; template using uset = unordered_set; template using umap = unordered_map; int main() { cin.tie(0); ios::sync_with_stdio(false); int l, n; cin >> l >> n; vector ws(n); rep(i,n) cin >> ws[i]; vector> dp(n + 1, vector(n + 1, l + 1)); dp[0][0] = 0; rep(i, n) rep(j, i + 1) { dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i][j] + ws[i]); } rep(i,n) { if (dp[n][n - i] <= l) { cout << n - i << endl; return 0; } } cout << 0 << endl; return 0; }