import sys


def getTheNumberOfCoin(n, m, c):
    T = {}
    for j in range(0, n+1):
        T[j] = 100000
    T[0] = 0

    for i in range(0, m):
        for j in range(c[i], n+1):
            T[j] = min(T[j], T[j-c[i]]+1)

    return T[n]


n, m = (int(x) for x in sys.stdin.readline().split())
c = sorted([int(x) for x in sys.stdin.readline().split()])

print(getTheNumberOfCoin(n, m, c)) import sys sys def getTheNumberOfCoin(n, m, c):
    T = {}
    for j in range(0, n+1):
        T[j] = 100000
    T[0] = 0

    for i in range(0, m):
        for j in range(c[i], n+1):
            T[j] = min(T[j], T[j-c[i]]+1)

    return T[n] getTheNumberOfCoin T = {} T {} for j in range(0, n+1):
        T[j] = 100000
     j range(0, n+1) range 0 n+1 n 1 T[j] = 100000 T[j] T j 100000 T[0] = 0 T[0] T 0 0 for i in range(0, m):
        for j in range(c[i], n+1):
            T[j] = min(T[j], T[j-c[i]]+1)

     i range(0, m) range 0 m for j in range(c[i], n+1):
            T[j] = min(T[j], T[j-c[i]]+1)

     j range(c[i], n+1) range c[i] c i n+1 n 1 T[j] = min(T[j], T[j-c[i]]+1) T[j] T j min(T[j], T[j-c[i]]+1) min T[j] T j T[j-c[i]]+1 T[j-c[i]] T j-c[i] j c[i] c i 1 return T[n] T[n] T n n n m m c c int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x n, m = (int(x) for x in sys.stdin.readline().split()) n (int(x) for x in sys.stdin.readline().split()) m int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x c = sorted([int(x) for x in sys.stdin.readline().split()]) c sorted([int(x) for x in sys.stdin.readline().split()]) sorted [int(x) for x in sys.stdin.readline().split()] print(getTheNumberOfCoin(n, m, c)) print getTheNumberOfCoin(n, m, c) getTheNumberOfCoin n m c m = (int(x) for x in sys.stdin.readline().split()) (int(x) for x in sys.stdin.readline().split()) m c = sorted([int(x) for x in sys.stdin.readline().split()]) sorted([int(x) for x in sys.stdin.readline().split()]) c n, m = (int(x) for x in sys.stdin.readline().split()) (int(x) for x in sys.stdin.readline().split()) n def getTheNumberOfCoin(n, m, c):
    T = {}
    for j in range(0, n+1):
        T[j] = 100000
    T[0] = 0

    for i in range(0, m):
        for j in range(c[i], n+1):
            T[j] = min(T[j], T[j-c[i]]+1)

    return T[n] def getTheNumberOfCoin(n, m, c):
    T = {}
    for j in range(0, n+1):
        T[j] = 100000
    T[0] = 0

    for i in range(0, m):
        for j in range(c[i], n+1):
            T[j] = min(T[j], T[j-c[i]]+1)

    return T[n] getTheNumberOfCoin
import sys


def getTheNumberOfCoin(n, m, c):
    T = {}
    for j in range(0, n+1):
        T[j] = 100000
    T[0] = 0

    for i in range(0, m):
        for j in range(c[i], n+1):
            T[j] = min(T[j], T[j-c[i]]+1)

    return T[n]


n, m = (int(x) for x in sys.stdin.readline().split())
c = sorted([int(x) for x in sys.stdin.readline().split()])

print(getTheNumberOfCoin(n, m, c))