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

#define BUF_SIZE 200

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define KINDS_MAX 20
#define NUM_MAX 50000
#define min(a,b) ((a) > (b) ? (b) : (a))

int asc(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main(void) {
    int cost, kinds;
    int dp[NUM_MAX+1];
    
    get_int2(&cost, &kinds);

    int coins[KINDS_MAX];
    int i, j;
    fget_array(coins, kinds);
    qsort(coins, kinds, sizeof(int), asc);

    // assume that coins[0] = 1;
    for(i = 0; i <= cost; i++) {
        dp[i] = i;
    }

    for(i = 2; i <= kinds; i++) {
        int c = coins[i-1];
        for(j = c; j <= cost; j++) {
            // how many coin you can use!
            dp[j] = min(dp[j],dp[j-c]+1);
        }
    }

    printf("%d\n", dp[cost]);
    return 0;
}

