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