#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;
//1209
const int maxn=21;
int minS;
int m,n;
int a[maxn];
void getRes(int sum,int n,int s) {//分别代表当前所取邮票总值,剩余邮票数,目前最少邮票数
if(sum==m){
if(s<minS)
minS=s;
return;
}
else if(sum>m|| n==0)
return ;
else{
getRes(sum,n-1,s); //要么不选这张
getRes(sum+a[n],n-1,s+1);//要么选这张
}
}
int main(){
// freopen("input.txt","r",stdin);
while(cin>>m>>n){
for(int i=1;i<=n;i++)
cin>>a[i];
minS=maxn;
getRes(0,n,0);
if(minS==maxn) cout<<0<<endl;
else
cout<<minS<<endl;
}
return 0;
}
/**************************************************************
Problem: 1209
User: cust123
Language: C++
Result: Accepted
Time:140 ms
Memory:1520 kb
****************************************************************/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;
//1209 dp做法
const int INF=1e5;
int dp[21][101];
int main(){
int m,n;
int sta[21];
// freopen("input.txt","r",stdin);
while(cin>>m>>n){
for(int i=1;i<=n;i++)
cin>>sta[i];
for(int j=1;j<=m;j++)
dp[0][j]=INF;
for(int i=1;i<=n;i++){
for(int j=m;j>=sta[i];j--){
dp[i][j]=min(dp[i-1][j],dp[i-1][j-sta[i]]+1);
}
for(int j=sta[i]-1;j>=0;j--)
dp[i][j]=dp[i-1][j];
}
if(dp[n][m]!=INF)
cout<<dp[n][m]<<endl;
else cout<<0<<endl;
}
return 0;
}
/**************************************************************
Problem: 1209
User: cust123
Language: C++
Result: Accepted
Time:160 ms
Memory:1528 kb
****************************************************************/