l = int(input()) n = int(input()) w = [int(i) for i in input().split()] check = [[False for i in range(l+1)] for j in range(n)] memo = [[0 for i in range(l+1)] for j in range(n)] def search(i,l): if i == n: return 0 elif check[i][l] == True: return memo[i][l] elif l < w[i]: return search(i+1,l) else: r1 = search(i+1, l) r2 = search(i+1, l - w[i]) + 1 r = max(r1,r2) check[i][l] = True memo[i][l] = r return r print(search(0,l))