L = int(input()) N = int(input()) W = [int(_) for _ in input().split()] W.sort() s: int = 0 cnt :int = 0 for n in W: if L >= s + n: s += n cnt += 1 else: print(cnt) break