H,W = map(int,input().split()) l = [] for _ in range(H): tmp = list(map(int,input().split())) for t in tmp: l.append(t) l.sort() ans = [] for i in range(H*W): ans.append(l[i]) if i > 0 and (i+1)%W == 0: print(*ans) ans = []