#include #include int main() { char x[100005]; scanf("%s", x); int i, j, n = strlen(x); int c[10]; for (i = 0; i < 10; i++) c[i] = 0; for (i = 0; i < n; i++) c[x[i] - '0']++; int count = 0; for (i = 0; i < 10; i++) if (c[i] > 0) count++; if (count == 1) { printf("-1\n"); return 0; } if (count == 2 && c[0] > 0) { i = 1; while (c[i] == 0) i++; if (c[i] == 1) { printf("-1\n"); return 0; } } j = 9; for (i = 0; i < n; i++) { while (c[j] == 0) j--; x[i] = j + '0'; c[j]--; } i = n - 1; while (x[i - 1] == x[i]) i--; i--; x[i] ^= x[n - 1]; x[n - 1] ^= x[i]; x[i] ^= x[n - 1]; printf("%s\n", x); return 0; }