#include<bits/stdc++.h>
#define I(w,e) for(int i=w;i<e;i++)
#define J(w,e) for(int j=w;j<e;j++)
#define K(w,e) for(int k=w;k<e;k++)
using namespace std;
bool complare(int f,int g)
{
return f>g;
}
int a[20005],b[20005];
int sz,sum;
int u=0;
int h=0;
int m=20005;
int t=0;
int doit(int h){
if(u<sz){
if(m>sz-u){
m=sz-u;
}
}
if(u==sz){
m=0;
t=1;
return 0;
}
if(t==1){
return 0;
}
I(h,sum){
if(t==1){
break;
}
if(b[i]==1){
continue;
}
else{
b[i]=1;
u+=a[i];
h=i;
doit(h+1);
b[i]=0;
u-=a[i];
}
}
}
int main()
{
cin>>sz>>sum;
I(0,sum){
cin>>a[i];
}
sort(a,a+sum-1,complare);
doit(0);
cout<<m;
return 0;
}