#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; constexpr ll mod = 998244353; const ll INF = mod * mod; typedef pairP; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair LP; typedef double ld; typedef pair LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); void solve() { int c, n; cin >> c >> n; vector dp(c + 1, mod); dp[0] = 0; vector a(n); rep(i, n)cin >> a[i]; rep(i, n) { rep(j, c-a[i]+1) { dp[j + a[i]] = min(dp[j + a[i]], dp[j] + 1); } } int ans = dp[c]; if (ans == mod)ans = -1; cout << ans << "\n"; } signed main() { //ios::sync_with_stdio(false); //cin.tie(0); //cout << fixed << setprecision(10); //init_f(); //expr(); //int t; cin >> t; rep(i, t) //while (cin >> n >> m>>s1>>s2>>t, n) solve(); return 0; }