L = int(input()) N = int(input()) w = [int(i) for i in input().split()] def search(i,l): if i == N: return 0 elif l < w[i]: return search(i+1,l) else: r1 = search(i+1, l) r2 = search(i+1, l - w[i]) + 1 return max(r1,r2) print(search(0,L))