#include<iostream>
#include<string.h>
using namespace std;

const int N = 1100; 
int v[N];
int f[N][N];
int main(void)
{
	int m,n;
	memset(f,0x3f,sizeof f);
	cin >> m >> n;
	for(int i = 1;i <= n;i++) cin >> v[i];
	f[0][0] = 0;
	for(int i = 1;i <= n;i++)
	{
		for(int j = m;j >= 0;j--)
		{
			f[i][j] = f[i - 1][j];
			if(j >= v[i]) 
				f[i][j] = min(f[i][j],f[i - 1][j - v[i]] + 1);
		}
	}
	if(f[n][m] == 0x3f3f3f3f) cout << "0" << endl;
	else cout << f[n][m] << endl;
	
	return 0;
}