L = int(input()) N = int(input()) W = list(map(int,input().split(" "))) size = 0 cnt = 0 while size <= L and len(W) > 0: size += W.pop(W.index(min(W))) if size <= L: cnt += 1 print(cnt)