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