l,n,*w=$<.map &:to_i;s=0;w.sort!;p n.times{|i|s+=w[i];break i if s>l}