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