H, W = map(int, input().split()) S = sum([input().split() for _ in range(H)], []) S.sort() for i in range(H): print(' '.join(S[i*W:i*W+W]))