a=int(input()) b=int(input()) c=sorted(map(int,input().split())) d=0 e=0 for i in range(b): d+=c[i] if d<=a: e+=1 else: break print(e)