#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int h,n;
int w[600];
long long int f[45010];
int main()
{
freopen("diet.in","r",stdin);
freopen("diet.out","w",stdout);
scanf("%d%d",&h,&n);
for(int i=1;i<=n;i++)
scanf("%d",&w[i]);
for(int i=1;i<=n;i++)
for(int j=h;j>=w[i];j--)
if(f[j-w[i]]+w[i]>f[j])
f[j]=f[j-w[i]]+w[i];
printf("%lld",f[h]);
fclose(stdin);
fclose(stdout);
return 0;
}