L = int(input()) N = int(input()) W = list(map(int, input().split())) Ws = sorted(W) cnt = 0 w = 0 for i in Ws: w += i if w <= L: cnt += 1 else: break print(cnt)