#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=50005;
const int maxm=5005;
int v,n;
int f[maxn],w[maxm];
int main()
{
freopen("hay4sale.in","r",stdin);
freopen("hay4sale.out","w",stdout);
scanf("%d%d",&v,&n);
for(register int i=1;i<=n;i++) scanf("%d",w+i);
for(register int i=1;i<=n;i++)
for(register int j=v;j>=w[i];j--) f[j]=max(f[j],f[j-w[i]]+w[i]);
printf("%d\n",f[v]);
return 0;
}