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