import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, M = map(int, readline().split())
    C = list(map(int, readline().split()))
    # dp[i] := i円払うのに必要な枚数
    dp = [INF] * (N+1)
    dp[0] = 0
    for c in C:
        if c<=N:
            for i in range(N-c+1):
                dp[i+c] = min(dp[i]+1, dp[i+c])
    print(dp[N])


if __name__ == '__main__':
    main()

 import sys sys read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline sys.setrecursionlimit(10 ** 8) sys.setrecursionlimit sys setrecursionlimit 10 ** 8 10 8 INF = float('inf') INF float('inf') float 'inf' MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 def main():
    N, M = map(int, readline().split())
    C = list(map(int, readline().split()))
    # dp[i] := i円払うのに必要な枚数
    dp = [INF] * (N+1)
    dp[0] = 0
    for c in C:
        if c<=N:
            for i in range(N-c+1):
                dp[i+c] = min(dp[i]+1, dp[i+c])
    print(dp[N]) main N, M = map(int, readline().split()) N map(int, readline().split()) map int readline().split() ().split () readline split M C = list(map(int, readline().split())) C list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split dp = [INF] * (N+1) dp [INF] * (N+1) [INF] INF N+1 N 1 dp[0] = 0 dp[0] dp 0 0 for c in C:
        if c<=N:
            for i in range(N-c+1):
                dp[i+c] = min(dp[i]+1, dp[i+c])
     c C if c<=N:
            for i in range(N-c+1):
                dp[i+c] = min(dp[i]+1, dp[i+c])
     c<=N c N for i in range(N-c+1):
                dp[i+c] = min(dp[i]+1, dp[i+c])
     i range(N-c+1) range N-c+1 N-c N c 1 dp[i+c] = min(dp[i]+1, dp[i+c]) dp[i+c] dp i+c i c min(dp[i]+1, dp[i+c]) min dp[i]+1 dp[i] dp i 1 dp[i+c] dp i+c i c print(dp[N]) print dp[N] dp N if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N, M = map(int, readline().split())
    C = list(map(int, readline().split()))
    # dp[i] := i円払うのに必要な枚数
    dp = [INF] * (N+1)
    dp[0] = 0
    for c in C:
        if c<=N:
            for i in range(N-c+1):
                dp[i+c] = min(dp[i]+1, dp[i+c])
    print(dp[N]) def main():
    N, M = map(int, readline().split())
    C = list(map(int, readline().split()))
    # dp[i] := i円払うのに必要な枚数
    dp = [INF] * (N+1)
    dp[0] = 0
    for c in C:
        if c<=N:
            for i in range(N-c+1):
                dp[i+c] = min(dp[i]+1, dp[i+c])
    print(dp[N]) main MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD read = sys.stdin.read sys.stdin.read read INF = float('inf') float('inf') INF readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, M = map(int, readline().split())
    C = list(map(int, readline().split()))
    # dp[i] := i円払うのに必要な枚数
    dp = [INF] * (N+1)
    dp[0] = 0
    for c in C:
        if c<=N:
            for i in range(N-c+1):
                dp[i+c] = min(dp[i]+1, dp[i+c])
    print(dp[N])


if __name__ == '__main__':
    main()


