r,c = gets.split.map(&:to_i) Array.new(r) {|_| gets }.map(&:split).flatten.map(&:to_i).sort.flatten.sort.each_slice(c).to_a.each{|a| puts a * ' '}