L = int(input()) input() W = list(map(int, input().split())) if L < min(W): print(0) elif L > sum(W): print(len(W)) else: W.sort() for i,x in enumerate(W): if L < sum(W[:i+1]): print(i) break