#coding:utf-8 L=input() N=input() W_str=raw_input().split() W=[int(i) for i in W_str] s=[] cnt=0 for i in sorted(W): cnt+=i if cnt <= L: s.append(i) else: break print len(s)