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