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