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(); boolean flg1 = false; int j = 0; for (int i = 9; i >= 0; i--) { if (a[i] > 0) { sb.append(i); a[i]--; j = i - 1; if (a[i] == 0) { flg1 = true; } break; } } for (int i = j; i >= 0; i--) { if (a[i] > 0) { if (flg1) { flg1 = false; } else { sb.append(i); a[i]--; break; } } } if (sb.length() < 2 || sb.charAt(0) == '0') { System.out.println(-1); return; } for (int i = 9; i >= 0; i--) { while (a[i] > 0) { sb.append(i); a[i]--; } } System.out.println(sb.toString()); } }