H, W = map(int, input().split()) A = [] for _ in range(H): A += list(map(int, input().split())) A = sorted(A) for h in range(H): print(*A[h*W:W+h*W])