use std::io::{Read, stdin}; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); let mut x = get() .as_bytes() .iter() .cloned() .collect::>(); x.sort(); let (p, _) = x .iter() .enumerate() .rfind(|(_,s)| **s == x[0]) .unwrap(); let find = x .iter() .enumerate() .find(|(_,s)| **s != x[0]); let ans = match find { None => "-1".to_string(), Some((i, _)) if i+1 == x.len() && x[0] == b'0' => "-1".to_string(), Some((i, _)) => { x.swap(p, i); x.reverse(); String::from_utf8(x).unwrap() } }; println!("{}", ans); }