#include<cstdio>
#include <fstream>
#define M 99999
using namespace std;
int h,n,i,v;
int s[M]={0},f[M]={0};
int Main()
{
freopen("diet.in","r",stdin);
freopen("diet.out","w",stdout);
scanf("%d%d",&h,&n);
for(i=1;i<=n;i++)
scanf("%d",&s[i]);
for(i=1;i<=n;i++)
for(v=h;v>=s[i];v--)
// if(f[v-s[i]]>f[v])
f[v]=max(f[v],f[v-s[i]]+s[i]);
printf("%d",f[h]);
return 0;
}
int work=Main();
int main(){;
}