# frozen_string_literal: true def solve A.flatten.sort.each_slice(W).map { _1.join(' ') }.join("\n") end H, W = gets.split.map(&:to_i) A = H.times.map { gets.split.map(&:to_i) } puts solve