L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() cnt = 0 total = 0 for i in W: total += i if L >= total: cnt += 1 else: break print(cnt)