l = int(input()) n = int(input()) wn = sorted(map(int,input().split())) count=0 v = 0 for wi in wn: if count+wi>l: break count+=wi v+=1 print(v)