#include <cstdio>
using namespace std;
int i=0,j=0,n=0,zui=0,zj,a[500]={0},f[45001]={0};
int main()
{
freopen("diet.in","r",stdin);
freopen("diet.out","w",stdout);
scanf("%d %d",&zui,&n);
for (i=0;i<n;i++) scanf("%d",&a[i]);
n--;
for (i=0;i<n;i++)
for (j=zui;j>=a[i];j--)
{
zj=a[i]+f[j-a[i]];
if(zj>f[j]) f[j]=zj;
}
zj=a[i]+f[zui-a[i]];
if (zj>f[zui]) f[zui]=zj;
printf("%d\n",f[zui]);
return(0);
}