import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); String x = sc.next(); sc.close(); int[] a = new int[10]; for (int i = 0; i < x.length(); i++) { a[x.charAt(i) - '0']++; } StringBuilder sb = new StringBuilder(); for (int i = 9; i >= 0; i--) { while (a[i] > 0) { sb.append(i); a[i]--; } } boolean flg = false; for (int i = sb.length() - 1; i > 0; i--) { if (sb.charAt(i) != sb.charAt(i - 1)) { char ch = sb.charAt(i); sb.setCharAt(i, sb.charAt(i - 1)); sb.setCharAt(i - 1, ch); flg = true; break; } } if (!flg || sb.charAt(0) == '0') { System.out.println(-1); return; } System.out.println(sb.toString()); } }