#1行目 width = int(input()) #2行目 blocknum = int(input()) #3行目 blocksize = input().split() blocksize.sort() sum = 0 ans = 0 for n in range(blocknum): if width - sum <= blocksize(n): sum += blocksize(n) ans += 1 else: break print(ans)