def ascan; gets.split.map(&:to_i); end N, M = ascan params = nil N.times do |i| player = ascan if !params params = player.map{|e| [e,[i]]} else M.times do |j| params[j] = [player[j], []] if params[j][0] < player[j] params[j][1] << i if params[j][0] <= player[j] end end p params.map{|e| e[1]}.reduce(:+).uniq.size end