#coding: utf-8 ##yuki_5 l=int(raw_input()) n=int(raw_input()) w=map(int,raw_input().split()) w.sort() res=0 count=0 for i in xrange(n): if res+w[i]<=l: res+=w[i] count+=1 else: break print count