import sys sys.setrecursionlimit(10 ** 6) def main(): l = int(input()) n = int(input()) ww = list(map(int, input().split())) ww.sort() s = 0 cnt = 0 for w in ww: s += w cnt += 1 if s > l: break else: cnt += 1 print(cnt - 1) main()