#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int h,n;
int wei[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",&wei[i]);
for(int i=1;i<=n;i++)
for(int j=h;j>=wei[i];j--)
if(f[j-wei[i]]+wei[i]>f[j])
f[j]=f[j-wei[i]]+wei[i];
printf("%lld",f[h]);
fclose(stdin);
fclose(stdout);
return 0;
}