#include<cstdio>
#define syy myson
using namespace std;
int c,h,w[10010],v[10010],f[100010],i,j;
int max(int a,int b)
{
return a>b?a:b;
}
int Main()
{
freopen("hay4sale.in","r",stdin);freopen("hay4sale.out","w",stdout);
scanf("%d%d",&c,&h);
for(i=1;i<=h;i++)
{
scanf("%d",&w[i]);
v[i]=w[i];
}
for(i=1;i<=h;i++)
for(j=c;j>=w[i];j--)
f[j]=max(f[j],f[j-w[i]]+v[i]);
printf("%d",f[c]);
return 0;
}
int main(){;}
int syy=Main();