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