#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#define MIN(a,b) a>b?b:a
int main() {
	int n,m,i,j,min,cnt,nn;
	int *C, *T;
	scanf("%d%d", &n, &m);
	n += 1;
	min = n;
	C = (int*)malloc(sizeof(int)*m);
	T = (int*)malloc(sizeof(int)*n*m);
	for (i = 0; i < m; i++) scanf("%d", C + i);
	for (j = 0; j < n; j++) T[j] = j;
	
	for (i = 1; i < m; i++) {
		for (j = 0; j < n; j++) {
			T[n*i + j] = MIN(T[n*(i-1)+j],T[(n*i)+j-C[i]]+1);
		}
	}
	for (i = 1,j=0; i <=m; i++) if (min > T[(n-1)*i+j])min = T[(n-1)*i+(j++)];
//	for (i = 0; i < m*n; i++) { printf("%3d ", T[i]); if ((i+1)%n == 0&&i!=0)puts(""); }
	printf("%d\n", min);
	free(C); free(T);
	return 0;
}