#include #include #include #include #include #include #include #include #include #include using namespace std; //#define __int64 long long #define long __int64 #define REP(i,a,b) for(int i=a;i= n){ return false; } x[op] = left / a[op]; while(a[op] >= 0){ if(func(op+1, left - a[op] * x[op], ans)){ return true; } if(x[op] == 0){ return false; } x[op] --; } x[op] = 0; return false; } int main(){ int ans = 0; cin >> total >> n; rep(i,n){ cin >> a[i]; } sort(a, a + n, greater()); //降順 if(func(0, total, ans)){ cout << ans << endl; }else{ cout << -1 << endl; } return 0; }