#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile

INF = float("inf")


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_A
    n, m = readi(2)
    coins = readi(m)
    dp = arr(n + 1, fill_value=INF)
    dp[0] = 0
    for i in range(n):
        for c in coins:
            if i + 1 - c >= 0:
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1)
    print(dp[n])


if __name__ == "__main__":
    main()
 import string string import sys sys from itertools import chain, dropwhile, takewhile INF = float("inf") INF float("inf") float "inf" def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])] read def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

     read_word w = lambda c: c in whitespaces w lambda c: c in whitespaces c in whitespaces c whitespaces c nw = lambda c: c not in whitespaces nw lambda c: c not in whitespaces c not in whitespaces c whitespaces c return f("".join(takewhile(nw, dropwhile(w, it)))) f("".join(takewhile(nw, dropwhile(w, it)))) f "".join(takewhile(nw, dropwhile(w, it))) "".join "" join takewhile(nw, dropwhile(w, it)) takewhile nw dropwhile(w, it) dropwhile w it if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])] not shape shape return read_word() read_word() read_word elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
     len(shape) == 1 len(shape) len shape 1 read_word() for _ in range(shape[0]) for _ in range(shape[0]) _ range(shape[0]) range shape[0] shape 0 for _ in range(shape[0]) read_word() read_word return [read_word() for _ in range(shape[0])] [read_word() for _ in range(shape[0])] elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])] len(shape) == 2 len(shape) len shape 2 [read_word() for _ in range(shape[1])] for _ in range(shape[0]) for _ in range(shape[0]) _ range(shape[0]) range shape[0] shape 0 for _ in range(shape[0]) [read_word() for _ in range(shape[1])] return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])] [[read_word() for _ in range(shape[1])] for _ in range(shape[0])] f=int f int it=chain.from_iterable(sys.stdin) it chain.from_iterable(sys.stdin) chain.from_iterable chain from_iterable sys.stdin sys stdin whitespaces=set(string.whitespace) whitespaces set(string.whitespace) set string.whitespace string whitespace *shape def readi(*shape):
    return read(*shape) readi return read(*shape) read(*shape) read *shape shape *shape def readi1(*shape):
    return [i - 1 for i in readi(*shape)] readi1 i - 1 for i in readi(*shape) for i in readi(*shape) i readi(*shape) readi *shape shape for i in readi(*shape) i - 1 i 1 return [i - 1 for i in readi(*shape)] [i - 1 for i in readi(*shape)] *shape def readf(*shape):
    return read(*shape, f=float) readf return read(*shape, f=float) read(*shape, f=float) read *shape shape f=float f float *shape def reads(*shape):
    return read(*shape, f=str) reads return read(*shape, f=str) read(*shape, f=str) read *shape shape f=str f str *shape def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])] arr if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])] len(shape) == 1 len(shape) len shape 1 return [fill_value] * shape[0] [fill_value] * shape[0] [fill_value] fill_value shape[0] shape 0 elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])] len(shape) == 2 len(shape) len shape 2 [fill_value] * shape[1] for _ in range(shape[0]) for _ in range(shape[0]) _ range(shape[0]) range shape[0] shape 0 for _ in range(shape[0]) [fill_value] * shape[1] [fill_value] fill_value shape[1] shape 1 return [[fill_value] * shape[1] for _ in range(shape[0])] [[fill_value] * shape[1] for _ in range(shape[0])] fill_value=0 fill_value 0 *shape def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    ) dbg print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    ) print ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()) ", ".join ", " join "{} = {}".format(k, repr(v)) "{} = {}".format "{} = {}" format k repr(v) repr v file=sys.stderr file sys.stderr sys stderr **kwargs def main():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_A
    n, m = readi(2)
    coins = readi(m)
    dp = arr(n + 1, fill_value=INF)
    dp[0] = 0
    for i in range(n):
        for c in coins:
            if i + 1 - c >= 0:
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1)
    print(dp[n]) main n, m = readi(2) n readi(2) readi 2 m coins = readi(m) coins readi(m) readi m dp = arr(n + 1, fill_value=INF) dp arr(n + 1, fill_value=INF) arr n + 1 n 1 fill_value=INF fill_value INF dp[0] = 0 dp[0] dp 0 0 for i in range(n):
        for c in coins:
            if i + 1 - c >= 0:
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1)
     i range(n) range n for c in coins:
            if i + 1 - c >= 0:
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1)
     c coins if i + 1 - c >= 0:
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1)
     i + 1 - c >= 0 i + 1 - c i + 1 i 1 c 0 dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1) dp[i + 1] dp i + 1 i 1 min(dp[i + 1], dp[i + 1 - c] + 1) min dp[i + 1] dp i + 1 i 1 dp[i + 1 - c] + 1 dp[i + 1 - c] dp i + 1 - c i + 1 i 1 c 1 print(dp[n]) print dp[n] dp n if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def readf(*shape):
    return read(*shape, f=float) def readf(*shape):
    return read(*shape, f=float) readf def reads(*shape):
    return read(*shape, f=str) def reads(*shape):
    return read(*shape, f=str) reads def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])] def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])] read def readi(*shape):
    return read(*shape) def readi(*shape):
    return read(*shape) readi INF = float("inf") float("inf") INF def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])] def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])] arr def readi1(*shape):
    return [i - 1 for i in readi(*shape)] def readi1(*shape):
    return [i - 1 for i in readi(*shape)] readi1 def main():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_A
    n, m = readi(2)
    coins = readi(m)
    dp = arr(n + 1, fill_value=INF)
    dp[0] = 0
    for i in range(n):
        for c in coins:
            if i + 1 - c >= 0:
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1)
    print(dp[n]) def main():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_A
    n, m = readi(2)
    coins = readi(m)
    dp = arr(n + 1, fill_value=INF)
    dp[0] = 0
    for i in range(n):
        for c in coins:
            if i + 1 - c >= 0:
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1)
    print(dp[n]) main def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    ) def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    ) dbg
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile

INF = float("inf")


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_A
    n, m = readi(2)
    coins = readi(m)
    dp = arr(n + 1, fill_value=INF)
    dp[0] = 0
    for i in range(n):
        for c in coins:
            if i + 1 - c >= 0:
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1)
    print(dp[n])


if __name__ == "__main__":
    main()

