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