import numpy as np H, W = map(int, input().split()) a = np.array([list(map(int, input().split())) for i in range(H)]) a = a.reshape(1, -1) a.sort() a = a.reshape(H, W) for e in a : print(*e)