import sys l=input() n=input() a=map(int,raw_input().split()) a.sort() sum=0 for i in range(n): sum+=a[i] if sum>l: print i sys.exit() print n