import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args){ Scanner stdIn = new Scanner(System.in); String x = stdIn.next(); char c[] = x.toCharArray(); char copy[] = new char[x.length()]; Arrays.sort(c); for(int i = 0; i < x.length(); i++){ copy[i] = c[x.length() - i - 1]; } boolean flag = false; for(int i = x.length() - 2; i >= 0; i--){ if(copy[x.length() - 1] != copy[i]){ int tmp = copy[i + 1]; copy[i + 1] = copy[i]; copy[i] = (char)tmp; flag = true; break; } } if(flag && copy[0] != '0'){ System.out.println(copy); }else{ System.out.println(-1); } } }