import numpy as np H, W = map(int, input().split()) S = sorted(map(int, open(0).read().split())) for i in range(H): print(*S[i*W:i*W+W])