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