h,w=gets.split(" ").map{|e| e.to_i} readlines.map{|e| e.split(" ").map{|e| e.to_i} }.flatten(1).sort.each_slice(w){|e| puts e.join(" ") }