L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() sum = 0 result = 0 for i in range(N): sum += W[i] if L < sum: result = i break elif L == sum: result = i + 1 break print(result)