l,n,*w=gets(p).split.map(&:to_i) w.sort! w<<(1<<30) p (0...n).bsearch{|i|w[0..i].inject(:+)>l}