def main():
    N, M = map(int, input().split())
    C = list(map(int, input().split()))
    dp = [float('inf')] * (N + 5)
    dp[0] = 0
    for i in range(N+1):
        for c in C:
            if i + c > N + 1:
                continue
            dp[i+c] = min(dp[i+c], dp[i] + 1)

    print(dp[N])


if __name__ == "__main__":
    main() def main():
    N, M = map(int, input().split())
    C = list(map(int, input().split()))
    dp = [float('inf')] * (N + 5)
    dp[0] = 0
    for i in range(N+1):
        for c in C:
            if i + c > N + 1:
                continue
            dp[i+c] = min(dp[i+c], dp[i] + 1)

    print(dp[N]) main N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M C = list(map(int, input().split())) C list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp = [float('inf')] * (N + 5) dp [float('inf')] * (N + 5) [float('inf')] float('inf') float 'inf' N + 5 N 5 dp[0] = 0 dp[0] dp 0 0 for i in range(N+1):
        for c in C:
            if i + c > N + 1:
                continue
            dp[i+c] = min(dp[i+c], dp[i] + 1)

     i range(N+1) range N+1 N 1 for c in C:
            if i + c > N + 1:
                continue
            dp[i+c] = min(dp[i+c], dp[i] + 1)

     c C if i + c > N + 1:
                continue
             i + c > N + 1 i + c i c N + 1 N 1 continue dp[i+c] = min(dp[i+c], dp[i] + 1) dp[i+c] dp i+c i c min(dp[i+c], dp[i] + 1) min dp[i+c] dp i+c i c dp[i] + 1 dp[i] dp i 1 print(dp[N]) print dp[N] dp N if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, M = map(int, input().split())
    C = list(map(int, input().split()))
    dp = [float('inf')] * (N + 5)
    dp[0] = 0
    for i in range(N+1):
        for c in C:
            if i + c > N + 1:
                continue
            dp[i+c] = min(dp[i+c], dp[i] + 1)

    print(dp[N]) def main():
    N, M = map(int, input().split())
    C = list(map(int, input().split()))
    dp = [float('inf')] * (N + 5)
    dp[0] = 0
    for i in range(N+1):
        for c in C:
            if i + c > N + 1:
                continue
            dp[i+c] = min(dp[i+c], dp[i] + 1)

    print(dp[N]) main
def main():
    N, M = map(int, input().split())
    C = list(map(int, input().split()))
    dp = [float('inf')] * (N + 5)
    dp[0] = 0
    for i in range(N+1):
        for c in C:
            if i + c > N + 1:
                continue
            dp[i+c] = min(dp[i+c], dp[i] + 1)

    print(dp[N])


if __name__ == "__main__":
    main()
