H, W, *A = map(int, open(0).read().split()) A.sort() A = iter(A) for _ in range(H): print(*[next(A) for _ in range(W)])