def resolve():
    Nyens, Mtypes = map(int, input().split())  # N円をM種類のコインで最小枚数で払うという問題
    types = list(map(int, input().split()))  # 何円玉があるかのリスト

    def knapsack(Nyens, Mtypes, types):
        # dp[i][j]:i種類目までのコイン限定でj円払うのに必要な最小枚数
        # 最小で無限枚必要として初期化
        dp = [[float('inf')] * (Nyens + 1) for _ in range(Mtypes + 1)]

        # 0円は0枚で払える
        for ii in range(Mtypes):
            dp[ii][0] = 0

        for i in range(Mtypes):
            for j in range(Nyens + 1):
                if j >= types[i]:  # 最小枚数更新の可能性
                    dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
                else:  # 可能性なし
                    dp[i + 1][j] = dp[i][j]

        return dp[Mtypes][Nyens]

    print(knapsack(Nyens, Mtypes, types))

resolve() def resolve():
    Nyens, Mtypes = map(int, input().split())  # N円をM種類のコインで最小枚数で払うという問題
    types = list(map(int, input().split()))  # 何円玉があるかのリスト

    def knapsack(Nyens, Mtypes, types):
        # dp[i][j]:i種類目までのコイン限定でj円払うのに必要な最小枚数
        # 最小で無限枚必要として初期化
        dp = [[float('inf')] * (Nyens + 1) for _ in range(Mtypes + 1)]

        # 0円は0枚で払える
        for ii in range(Mtypes):
            dp[ii][0] = 0

        for i in range(Mtypes):
            for j in range(Nyens + 1):
                if j >= types[i]:  # 最小枚数更新の可能性
                    dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
                else:  # 可能性なし
                    dp[i + 1][j] = dp[i][j]

        return dp[Mtypes][Nyens]

    print(knapsack(Nyens, Mtypes, types)) resolve Nyens, Mtypes = map(int, input().split()) Nyens map(int, input().split()) map int input().split() ().split () input split Mtypes types = list(map(int, input().split())) types list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def knapsack(Nyens, Mtypes, types):
        # dp[i][j]:i種類目までのコイン限定でj円払うのに必要な最小枚数
        # 最小で無限枚必要として初期化
        dp = [[float('inf')] * (Nyens + 1) for _ in range(Mtypes + 1)]

        # 0円は0枚で払える
        for ii in range(Mtypes):
            dp[ii][0] = 0

        for i in range(Mtypes):
            for j in range(Nyens + 1):
                if j >= types[i]:  # 最小枚数更新の可能性
                    dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
                else:  # 可能性なし
                    dp[i + 1][j] = dp[i][j]

        return dp[Mtypes][Nyens]

     knapsack [float('inf')] * (Nyens + 1) for _ in range(Mtypes + 1) for _ in range(Mtypes + 1) _ range(Mtypes + 1) range Mtypes + 1 Mtypes 1 for _ in range(Mtypes + 1) [float('inf')] * (Nyens + 1) [float('inf')] float('inf') float 'inf' Nyens + 1 Nyens 1 dp = [[float('inf')] * (Nyens + 1) for _ in range(Mtypes + 1)] dp [[float('inf')] * (Nyens + 1) for _ in range(Mtypes + 1)] for ii in range(Mtypes):
            dp[ii][0] = 0

         ii range(Mtypes) range Mtypes dp[ii][0] = 0 dp[ii][0] [ii] dp ii 0 0 for i in range(Mtypes):
            for j in range(Nyens + 1):
                if j >= types[i]:  # 最小枚数更新の可能性
                    dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
                else:  # 可能性なし
                    dp[i + 1][j] = dp[i][j]

         i range(Mtypes) range Mtypes for j in range(Nyens + 1):
                if j >= types[i]:  # 最小枚数更新の可能性
                    dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
                else:  # 可能性なし
                    dp[i + 1][j] = dp[i][j]

         j range(Nyens + 1) range Nyens + 1 Nyens 1 if j >= types[i]:  # 最小枚数更新の可能性
                    dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
                else:  # 可能性なし
                    dp[i + 1][j] = dp[i][j]

         j >= types[i] j types[i] types i dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1) dp[i + 1][j] [i + 1] dp i + 1 i 1 j min(dp[i][j], dp[i + 1][j - types[i]] + 1) min dp[i][j] [i] dp i j dp[i + 1][j - types[i]] + 1 dp[i + 1][j - types[i]] [i + 1] dp i + 1 i 1 j - types[i] j types[i] types i 1 dp[i + 1][j] = dp[i][j] dp[i + 1][j] [i + 1] dp i + 1 i 1 j dp[i][j] [i] dp i j return dp[Mtypes][Nyens] dp[Mtypes][Nyens] [Mtypes] dp Mtypes Nyens Nyens Nyens Mtypes Mtypes types types print(knapsack(Nyens, Mtypes, types)) print knapsack(Nyens, Mtypes, types) knapsack Nyens Mtypes types resolve() resolve def resolve():
    Nyens, Mtypes = map(int, input().split())  # N円をM種類のコインで最小枚数で払うという問題
    types = list(map(int, input().split()))  # 何円玉があるかのリスト

    def knapsack(Nyens, Mtypes, types):
        # dp[i][j]:i種類目までのコイン限定でj円払うのに必要な最小枚数
        # 最小で無限枚必要として初期化
        dp = [[float('inf')] * (Nyens + 1) for _ in range(Mtypes + 1)]

        # 0円は0枚で払える
        for ii in range(Mtypes):
            dp[ii][0] = 0

        for i in range(Mtypes):
            for j in range(Nyens + 1):
                if j >= types[i]:  # 最小枚数更新の可能性
                    dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
                else:  # 可能性なし
                    dp[i + 1][j] = dp[i][j]

        return dp[Mtypes][Nyens]

    print(knapsack(Nyens, Mtypes, types)) def resolve():
    Nyens, Mtypes = map(int, input().split())  # N円をM種類のコインで最小枚数で払うという問題
    types = list(map(int, input().split()))  # 何円玉があるかのリスト

    def knapsack(Nyens, Mtypes, types):
        # dp[i][j]:i種類目までのコイン限定でj円払うのに必要な最小枚数
        # 最小で無限枚必要として初期化
        dp = [[float('inf')] * (Nyens + 1) for _ in range(Mtypes + 1)]

        # 0円は0枚で払える
        for ii in range(Mtypes):
            dp[ii][0] = 0

        for i in range(Mtypes):
            for j in range(Nyens + 1):
                if j >= types[i]:  # 最小枚数更新の可能性
                    dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
                else:  # 可能性なし
                    dp[i + 1][j] = dp[i][j]

        return dp[Mtypes][Nyens]

    print(knapsack(Nyens, Mtypes, types)) resolve
def resolve():
    Nyens, Mtypes = map(int, input().split())  # N円をM種類のコインで最小枚数で払うという問題
    types = list(map(int, input().split()))  # 何円玉があるかのリスト

    def knapsack(Nyens, Mtypes, types):
        # dp[i][j]:i種類目までのコイン限定でj円払うのに必要な最小枚数
        # 最小で無限枚必要として初期化
        dp = [[float('inf')] * (Nyens + 1) for _ in range(Mtypes + 1)]

        # 0円は0枚で払える
        for ii in range(Mtypes):
            dp[ii][0] = 0

        for i in range(Mtypes):
            for j in range(Nyens + 1):
                if j >= types[i]:  # 最小枚数更新の可能性
                    dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
                else:  # 可能性なし
                    dp[i + 1][j] = dp[i][j]

        return dp[Mtypes][Nyens]

    print(knapsack(Nyens, Mtypes, types))

resolve()
