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