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