#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for1(i,a,b) for(ll i=(ll)a;i<=(ll)b;++i)
#define for0(i,a,b) for(ll i=(ll)a;i>=(ll)b;--i)
const int N = 1, mod = 1;
ll n, m, k, o[1010], maxx, dp[30000010];
int main (){
cin >>n >>m;
for1 (i, 1, m){
cin >>o[i];
maxx = max (maxx, o[i]);
}
for1 (j, 1, m){
for1 (i, o[j], maxx*n){
if (dp[i] == 0) dp[i] = 1e17;
dp[i] = min (dp[i], dp[i-o[j]]+1);
}
}
for (ll i = 1;;++ i){
if (dp[i] > n or dp[i] == 0){
cout <<i-1;
return 0;
}
}
return 0;
}