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