l = int(input()) n = int(input()) W = list(map(int, input().split())) W.sort() curr = 0 ans = 0 for i in range(n): if curr + W[i] > l: break ans += 1 curr += W[i] print(ans)