#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
    long long S, N;
    cin>>S>>N;
    long long mas[N];
    for (long long i=0; i<N; i++){
        cin>>mas[i];
    }
    for (long long i=0; i<N-1; i++){
        for (long long q=0; q<N-1-i; q++){
            if (mas[q]<mas[q+1]){
                swap (mas[q], mas[q+1]);
            }
        }
    }
    long long br=0, br2=0;
    for (long long i=0; i<N; i++)
    {
        while (mas[i]<=S){
            S=S-mas[i];
            br++;
        }
    }
    for (long long i=1; i<N; i++)
    {
        while (mas[i]<=S){
            S=S-mas[i];
            br2++;
        }
    }
    if (br<br2){
    cout<<br;
    }
    else cout<<br2;
    return 0;
}
