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