#include<bits//stdc++.h>
#include<algorithm>
#include<iterator>
using namespace std;

int s;
int n;
int a[2000];
int minsol=20000;
int needed=0;
int nownum=0;
int temp;

int Attempt(int card, int num)
{
    needed-=a[card]*num;
    nownum+=num;
    if(needed==0){
        if(nownum<minsol){
            minsol=nownum;
        }
    }
    else if(card>=n){

    }
    else{
        temp = needed/a[card+1];
        for(int i=0; i<=temp; i++){
            Attempt(card+1, i);
        }
    }
    needed+=a[card]*num;
    nownum-=num;
}

int main()
{
    cin>>s>>n;
    needed=s;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int l=0; l<n; l++)
    {
        for(int i=0; i<n-1; i++)
        {
            if(a[i]<a[i+1])
            {
                swap(a[i],a[i+1]);
            }
        }
    }
    temp = needed/a[0];
    for(int i=0;i<=temp;i++){
        Attempt(0, i);
    }

    cout<<minsol;
    return 0;
}
