L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() sumW = 0 for i in range(N) : sumW += W[i] if sumW - L > 0: break print(i)