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