import numpy as np H, W = map(int, input().split()) S = sorted(open(0).read().split()) for i in range(H): print(*S[i*W:i*W+W])