#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<string.h>

int n,m,*arr,*mem;

int min(int x, int y)
{
    return x<y ? x :y;
}

int min_coin_change(int n) 
{
    if(n==0) return 0;
    if(mem[n] != -1) return mem[n];

    int s_rlt, rlt = INT_MAX;

    for(int i=0; i<m; i++)
    {
        if(arr[i] <= n)
        {
            s_rlt = min_coin_change(n-arr[i]);
        }

        if(s_rlt != INT_MAX) rlt = min(rlt,s_rlt+1);
    }

    return mem[n] = rlt;
    
}

int main()
{
    scanf("%d %d",&n,&m);
    arr = (int*)malloc(sizeof(int)*m);
    mem = (int*)malloc(sizeof(int)*(n+10));
    memset(mem,-1,sizeof(int)*(n+10));

    for(int i=0; i<m; i++)
    {
        scanf("%d",&arr[i]);
    }
    
    printf("%d\n",min_coin_change(n));

    free(arr);
    free(mem);
    return 0;
}
