#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; const int MAX_N = 17; int T, N, t[MAX_N], sm[1 << MAX_N], g[1 << MAX_N]; void solve() { cin >> T >> N; rep(i, N)cin >> t[i]; rep(S, 1 << N) { g[S] = N; rep(i, N) if (S >> i & 1) sm[S] += t[i]; } g[0] = 0; const int A = (1 << N) - 1; rep(S, 1 << N) { int U = A ^ S, V = U; do { if (sm[V] <= T) { smin(g[S | V], g[S] + 1); } V = (V - 1)&U; } while (U != V); } cout << g[A] << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }