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