#include <stdio.h>
int power(int x, int y) {
int i = 1, last = 1;
while (i <= y) {
last = last * x;
i++;
}
return last;
}
int main() {
int x, x_save, count = 0, o = 0;
scanf("%d", &x);
x_save = x;
while (x > 0) {
count++;
x = x / 10;
}
int a[count];
for (int i = count - 1; i >= 0; i--) {
a[i] = x_save % 10;
x_save = x_save / 10;
}
long long int max = 0;
int times = count * count, last = count - 1;
int b[times];
for (int i = 0; i < count; i++) {
for (last = count - 1; last >= 0; last--) {
int temp = a[i];
a[i] = a[last];
a[last] = temp;
for (int j = count - 1; j >= 0; j--) {
max += power(10, j) * a[count - j];
}
} //
b[o] = max;
o++;
}
int max_max = b[0];
for (int i = 0; i < times; i++) {
if (b[i] > max_max) {
max_max = b[i];
}
}
printf("%d", max_max);
return 0;
}