H, W = map(int,input().split()) li = [] for _ in range(H) : li += list(map(int, input().split())) li.sort() for i in range(H) : print(*li[i * W :(i+1) * W])