import algorithm
     , sequtils
     , strutils
     , sugar

let
  hw =
    stdin
    .readLine
    .split
    .map parseInt
  h = hw[0]
  xs =
    newSeq
    .collect:
      for _ in 0 ..< h:
        let
          ys = toSeq split readLine stdin
        ys.filterIt(it != "")
  result =
    xs
    .concat
    .sorted
    .distribute(h)
    .mapIt(it.join " ")
    .join "\n"

echo result