n,m=map(int,input().split()) lst=[] for _ in range(n): lst+=map(int,input().split()) lst.sort() for i in range(n): print(*lst[i*m:(i+1)*m])