def E(S, N):
    T = S[::-1]
    U = S+T
    return sorted([U[i:N+i] for i in range(N)])[:3]

N, K = input().split()
N, K = int(N), int(K)
S = [input()]

for i in range(K):
    memory = []
    for s in S:
        memory.append(E(s, N))
    S = sorted([s for i in range(len(memory)) for s in memory[i]])[:3]
print(sorted(S)[0])