l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() sum = 0 for i in range(n): sum = sum + w[i] if sum > l: break print(i)