L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() res = 0 count = 0 for i in range(N): if res > L: break else: res += W[i] count += 1 if res>L: print(count-1) else: print(count)