import sys
readline = sys.stdin.readline
INF = 10 ** 10


def main():
    N, M = map(int, readline().rstrip().split())
    C = list(map(int, readline().rstrip().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in C:
        for i in range(c, N+1):
            dp[i] = min(dp[i], dp[i-c] + 1)
    
    print(dp[N])


if __name__ == '__main__':
    main() import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline INF = 10 ** 10 INF 10 ** 10 10 10 def main():
    N, M = map(int, readline().rstrip().split())
    C = list(map(int, readline().rstrip().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in C:
        for i in range(c, N+1):
            dp[i] = min(dp[i], dp[i-c] + 1)
    
    print(dp[N]) main N, M = map(int, readline().rstrip().split()) N map(int, readline().rstrip().split()) map int readline().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () readline rstrip split M C = list(map(int, readline().rstrip().split())) C list(map(int, readline().rstrip().split())) list map(int, readline().rstrip().split()) map int readline().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () readline rstrip 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:
        for i in range(c, N+1):
            dp[i] = min(dp[i], dp[i-c] + 1)
    
     c C for i in range(c, N+1):
            dp[i] = min(dp[i], dp[i-c] + 1)
    
     i range(c, N+1) range c N+1 N 1 dp[i] = min(dp[i], dp[i-c] + 1) dp[i] dp i min(dp[i], dp[i-c] + 1) min dp[i] dp i dp[i-c] + 1 dp[i-c] dp i-c i c 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, readline().rstrip().split())
    C = list(map(int, readline().rstrip().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in C:
        for i in range(c, N+1):
            dp[i] = min(dp[i], dp[i-c] + 1)
    
    print(dp[N]) def main():
    N, M = map(int, readline().rstrip().split())
    C = list(map(int, readline().rstrip().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in C:
        for i in range(c, N+1):
            dp[i] = min(dp[i], dp[i-c] + 1)
    
    print(dp[N]) main readline = sys.stdin.readline sys.stdin.readline readline INF = 10 ** 10 10 ** 10 INF
import sys
readline = sys.stdin.readline
INF = 10 ** 10


def main():
    N, M = map(int, readline().rstrip().split())
    C = list(map(int, readline().rstrip().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in C:
        for i in range(c, N+1):
            dp[i] = min(dp[i], dp[i-c] + 1)
    
    print(dp[N])


if __name__ == '__main__':
    main()
