L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() sumW = 0 ans = 0 while sumW+W[ans] <= L: sumW += W[ans] ans += 1 if ans == N: break print(ans)