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