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