#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXS = 20000 + 10;
const int MAXN = 2000 + 10;
const int INF  = 1e9;

int n, s;
int a[MAXN];
int dp[MAXS][2];
void solve()
{
    for (int idx = 1 ; idx <= n ; ++idx)
    {
        for (int sum = 1 ; sum <= s ; ++sum)
        {
            dp[sum][0] = INF;
            if (sum < a[idx])
            {
                dp[sum][idx&1] = dp[sum][!(idx&1)];
                continue;
            }
            dp[sum][idx&1] = std::min(dp[sum - a[idx]][idx&1] + 1, dp[sum][!(idx&1)]);
        }
    }

    std::cout << dp[s][n&1] << '\n';
}

void read()
{
    std::cin >> s >> n;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i];
    }
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    return 0;
}
