L=int(input()) N=int(input()) W=sorted(list(map(int,input().split()))) ans,W_sum=0,W[0] while W_sum<=L and ans<=N: W_sum+=W[ans+1] ans+=1 print(ans)