#include<stdio.h>
#include<stdlib.h>
#define min(a, b) (((a)<(b)) ? (a) : (b))

int c[20] = { 0 };
int memo[50010][20] = {{0}};

int min_coin(int amount, int coinnum);

int main() {
	int n, m, i;
	scanf("%d %d", &n, &m);
	for (i = 0; i < m; i++) scanf("%d", &c[i]);
	printf("%d\n", min_coin(n, m - 1));
	return 0;
}

int min_coin(int amount, int coinnum) {
	if (memo[amount][coinnum] == 0) {
		if (amount < 0 || coinnum < 0) return 50001;
		else if (amount == c[coinnum]) {
			memo[amount][coinnum] = 1;
			return memo[amount][coinnum];
		}
		else {
			memo[amount][coinnum] = min(min_coin(amount, coinnum - 1), min_coin(amount - c[coinnum], coinnum) + 1);
			return memo[amount][coinnum];
		}
	}
	else return memo[amount][coinnum];
}