#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int val[60],getnum[30000000];
int minint(int a,int b)
{
if (a<b)
return(a);
return(b);
}
int main(void)
{
freopen("stamps.in","r",stdin);
freopen("stamps.out","w",stdout);
int i,j,n,lim;
bool flag;
cin>>lim>>n;
for (i=1;i<=n;i++)
cin>>val[i];
getnum[0]=0;
i=1;
while (true)
{
flag=false;
for (j=1;j<=n;j++)
{
if (i-val[j]<0)
continue;
if (!flag)
{
flag=true;
getnum[i]=getnum[i-val[j]]+1;
}
else
{
getnum[i]=minint(getnum[i],getnum[i-val[j]]+1);
}
}
if (!flag)
break;
if (getnum[i]>lim)
break;
i++;
}
i--;
cout<<i<<endl;
return(0);
}