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