n,m=gets.split.map &:to_i c=gets.split.map(&:to_i).sort a=0 (0...n).each{|i| d=[m,c[i]].min m-=d c[i]-=d a+=1 if c[i]==0} p a