h,w = map(int,input().split()) from collections import Counter result = [] for i in range(h): result += list(map(int,input().split())) result = dict(sorted(Counter(result).items())) result2 = [] for key,value in result.items(): result2+=[int(key)]*value result3 = [] for i in range(0,h*w,w): print(*result2[i:i+w])