def main(): H, W = map(int, input().split()) A = [] for i in range(H): A.extend(map(int, input().split())) for i, v in enumerate(sorted(A)): print(v, end=' ' if i % W != W-1 else '\n') if __name__ == '__main__': main()