L=int(input()) N=int(input()) p=sorted(map(int,input().split())) sm=0 for i in range(N): sm+=p[i] if sm>L: break else: i+=1 print(i)