l=int(input()) n=int(input()) w=list(map(int,input().split())) w.sort() len=0 for i in range(n): len+=w[i] if len>l: print(i) exit() print(n)