import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): H, W = getlist() L = [] for i in range(H): a = getlist() L += a L.sort() ans = [[0] * W for i in range(H)] for i in range(H): for j in range(W): ans[i][j] = L[i * H + j] for i in range(H): print(*ans[i]) if __name__ == '__main__': main()