h, w = map(int, input().split()) a = list() for i in range(h): a += map(int, input().split()) a.sort() for i in range(h): ans = a[i * w : (i + 1) * w] print(*ans)