import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, m = list(map(int, input().strip().split()))
    c = [0] + sorted(list(map(int, input().strip().split())))
    dp = [[0] * (n+1) for _ in range(m+1)]
    dp[0] = [INF] * (n+1)
    dp[0][0] = 0
    for i in range(1, m+1):
        for j in range(n+1):
            if j-c[i] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)

    print(dp[m][n])

if __name__ == '__main__':
    main()
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from operator import itemgetter sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 INF = 10**30 INF 10**30 10 30 def main():
    n, m = list(map(int, input().strip().split()))
    c = [0] + sorted(list(map(int, input().strip().split())))
    dp = [[0] * (n+1) for _ in range(m+1)]
    dp[0] = [INF] * (n+1)
    dp[0][0] = 0
    for i in range(1, m+1):
        for j in range(n+1):
            if j-c[i] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)

    print(dp[m][n]) main n, m = list(map(int, input().strip().split())) n list(map(int, input().strip().split())) list map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split m c = [0] + sorted(list(map(int, input().strip().split()))) c [0] + sorted(list(map(int, input().strip().split()))) [0] 0 sorted(list(map(int, input().strip().split()))) sorted list(map(int, input().strip().split())) list map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split [0] * (n+1) for _ in range(m+1) for _ in range(m+1) _ range(m+1) range m+1 m 1 for _ in range(m+1) [0] * (n+1) [0] 0 n+1 n 1 dp = [[0] * (n+1) for _ in range(m+1)] dp [[0] * (n+1) for _ in range(m+1)] dp[0] = [INF] * (n+1) dp[0] dp 0 [INF] * (n+1) [INF] INF n+1 n 1 dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(1, m+1):
        for j in range(n+1):
            if j-c[i] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)

     i range(1, m+1) range 1 m+1 m 1 for j in range(n+1):
            if j-c[i] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)

     j range(n+1) range n+1 n 1 if j-c[i] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)

     j-c[i] < 0 j-c[i] j c[i] c i 0 dp[i][j] = dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1) dp[i][j] [i] dp i j min(dp[i-1][j], dp[i][j-c[i]]+1) min dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-c[i]]+1 dp[i][j-c[i]] [i] dp i j-c[i] j c[i] c i 1 print(dp[m][n]) print dp[m][n] [m] dp m n if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main input = sys.stdin.readline sys.stdin.readline input INF = 10**30 10**30 INF def main():
    n, m = list(map(int, input().strip().split()))
    c = [0] + sorted(list(map(int, input().strip().split())))
    dp = [[0] * (n+1) for _ in range(m+1)]
    dp[0] = [INF] * (n+1)
    dp[0][0] = 0
    for i in range(1, m+1):
        for j in range(n+1):
            if j-c[i] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)

    print(dp[m][n]) def main():
    n, m = list(map(int, input().strip().split()))
    c = [0] + sorted(list(map(int, input().strip().split())))
    dp = [[0] * (n+1) for _ in range(m+1)]
    dp[0] = [INF] * (n+1)
    dp[0][0] = 0
    for i in range(1, m+1):
        for j in range(n+1):
            if j-c[i] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)

    print(dp[m][n]) main
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, m = list(map(int, input().strip().split()))
    c = [0] + sorted(list(map(int, input().strip().split())))
    dp = [[0] * (n+1) for _ in range(m+1)]
    dp[0] = [INF] * (n+1)
    dp[0][0] = 0
    for i in range(1, m+1):
        for j in range(n+1):
            if j-c[i] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1)

    print(dp[m][n])

if __name__ == '__main__':
    main()

