L,N,*W=$<.read.split.map &:to_i cnt,sum=0,0 r=W.sort.each.with_index(1) do |v,i| if sum+v < L sum+=v cnt+=1 end end puts cnt