import java.util.Arrays; import java.util.Scanner; public class HelloWorld { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int number_rows = sc.nextInt(); int number_columns = sc.nextInt(); int[] data = new int[number_columns * number_rows]; for (int i = 0; i < number_rows * number_columns; i ++) { data[i] = sc.nextInt(); } Arrays.sort(data); for (int i = 0; i < number_rows; i++) { for (int j = 0; j < number_columns; j++) { System.out.print(data[i * number_columns + j]); if (j != number_columns - 1) { System.out.print(" "); } } System.out.println(""); } } }