#include using namespace std; typedef ostringstream OSS; typedef istringstream ISS; typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VVI; typedef vector VLL; typedef vector VVLL; typedef vector VD; typedef vector VVD; typedef vector VS; typedef vector VVS; typedef vector VB; typedef vector VVB; typedef vector VPII; #define fst first #define snd second // #define Y first // #define X second #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) (x).begin(),(x).end() #define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY)) #define DUMP( x ) cerr << #x << " = " << ( x ) << endl #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define REP(i, init, N) for (int i = (init); i < (int)(N); i++) template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; }; template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); }; const int INF = 0x3f3f3f3f; const LL INFL = 0x3f3f3f3f3f3f3f3fLL; const double DINF = 0x3f3f3f3f; const int DX[]={1,0,-1,0},DY[]={0,-1,0,1}; const double EPS = 1e-12; //const double PI = acos(-1.0); int main(void) { int C, N; cin >> C >> N; VI as(N); for (auto &a : as) cin >> a; VVI dp(N + 1, VI(C + 1, INF)); dp[0][0] = 0; rep(i, N) { rep(j, C + 1) { if (dp[i][j] == INF) continue; int c = j; int v = dp[i][j]; dp[i + 1][c] = min(dp[i + 1][c], v); c += as[i]; v += 1; if (c > C) continue; dp[i][c] = min(dp[i][c], v); } } int ans = dp[N][C]; cout << (ans == INF ? -1 : ans) << endl; return 0; }