w = input()
lst = []
for i in range(len(w)-2):
for j in range(i+1, len(w)-1):
for k in range(j+1, len(w)):
t = w[:j][::-1] + w[j:k][::-1] + w[k:][::-1]
lst.append(t)
print(min(lst))
w = input()
lst = []
for i in range(len(w)-2):
for j in range(i+1, len(w)-1):
for k in range(j+1, len(w)):
t = w[:j][::-1] + w[j:k][::-1] + w[k:][::-1]
lst.append(t)
print(min(lst))