#include<iostream>
#include<algorithm>
#define endl '\n'
using namespace std;
int s,n,num[2005],dp[20005][2005];
int minim(int sum,int pos)
{
    if(sum<0) return 100000000;
    if(pos==0 || sum==0) return sum;
    if(dp[sum][pos]) return dp[sum][pos];

    return dp[sum][pos]=min(minim(sum-num[pos],pos)+1,minim(sum,pos-1));
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>s>>n;

    for(int i=0;i<n;i++)
        cin>>num[i];

    sort(num,num+n);

    cout<<minim(s,n-1)<<endl;
}



