from typing import List


def changes(amount: int, kind: int, coins: List[int]) -> int:

    T: List[int] = [50001] * (amount + 1)
    T[0] = 0

    for i in range(kind):
        for j in range(coins[i], amount + 1):
            T[j] = min(T[j], T[j - coins[i]] + 1)

    return T[amount]


def main() -> None:
    n, m = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]

    print(changes(n, m, c))


main()
 from typing import List def changes(amount: int, kind: int, coins: List[int]) -> int:

    T: List[int] = [50001] * (amount + 1)
    T[0] = 0

    for i in range(kind):
        for j in range(coins[i], amount + 1):
            T[j] = min(T[j], T[j - coins[i]] + 1)

    return T[amount] changes T: List[int] = [50001] * (amount + 1) T [50001] * (amount + 1) [50001] 50001 amount + 1 amount 1 T[0] = 0 T[0] T 0 0 for i in range(kind):
        for j in range(coins[i], amount + 1):
            T[j] = min(T[j], T[j - coins[i]] + 1)

     i range(kind) range kind for j in range(coins[i], amount + 1):
            T[j] = min(T[j], T[j - coins[i]] + 1)

     j range(coins[i], amount + 1) range coins[i] coins i amount + 1 amount 1 T[j] = min(T[j], T[j - coins[i]] + 1) T[j] T j min(T[j], T[j - coins[i]] + 1) min T[j] T j T[j - coins[i]] + 1 T[j - coins[i]] T j - coins[i] j coins[i] coins i 1 return T[amount] T[amount] T amount amount: int amount kind: int kind coins: List[int] coins def main() -> None:
    n, m = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]

    print(changes(n, m, c)) main int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n, m = [int(x) for x in input().split()] n [int(x) for x in input().split()] m int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x c = [int(x) for x in input().split()] c [int(x) for x in input().split()] print(changes(n, m, c)) print changes(n, m, c) changes n m c main() main def changes(amount: int, kind: int, coins: List[int]) -> int:

    T: List[int] = [50001] * (amount + 1)
    T[0] = 0

    for i in range(kind):
        for j in range(coins[i], amount + 1):
            T[j] = min(T[j], T[j - coins[i]] + 1)

    return T[amount] def changes(amount: int, kind: int, coins: List[int]) -> int:

    T: List[int] = [50001] * (amount + 1)
    T[0] = 0

    for i in range(kind):
        for j in range(coins[i], amount + 1):
            T[j] = min(T[j], T[j - coins[i]] + 1)

    return T[amount] changes def main() -> None:
    n, m = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]

    print(changes(n, m, c)) def main() -> None:
    n, m = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]

    print(changes(n, m, c)) main
from typing import List


def changes(amount: int, kind: int, coins: List[int]) -> int:

    T: List[int] = [50001] * (amount + 1)
    T[0] = 0

    for i in range(kind):
        for j in range(coins[i], amount + 1):
            T[j] = min(T[j], T[j - coins[i]] + 1)

    return T[amount]


def main() -> None:
    n, m = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]

    print(changes(n, m, c))


main()

