H,W=map(int,input().split()) a=[] for i in range(H): for x in input().split(): a.append(x) a.sort() for i in range(H): print(*a[W*i:W*(i+1)])