include
include
include
include
include
include
include
include
using namespace std;
int v,n,ti[33];
int ans;
int f[33][20010];
int main()
{
cin>>v>>n;
for(int i=1;i<=n;i++) cin>>ti[i];
for(int i=1;i<=n;i++){
for(int j=v;j>=0;j--){
f[i][j]=max(f[i][j],f[i-1][j]);
if(j >= ti[i])
f[i][j]=max(f[i][j],f[i-1][j-ti[i]]+ti[i]);
}
}
ans=f[n][v];
ans=v-ans;
cout<<ans<<endl;
return 0;
}
/*
10 3
1
5
7
*/