import java.util.Scanner object Main extends App { val sc = new Scanner(System.in) val h = sc.nextInt val w = sc.nextInt println(Array.fill(h)(Array.fill(w)(sc.nextInt)).flatten.sorted.grouped(5).map(_.mkString(" ")).mkString("\n")) }