def convert_1d_to_2d(s, c): return [s[i:i + c] for i in range(0, len(s), c)] h, w = map(int, input().split()) s = [list(map(int, input().split())) for _ in range(h)] t = [] for i in range(h): for j in range(w): t.append(s[i][j]) t.sort() li = convert_1d_to_2d(t, w) for i in range(h): print(*li[i])