char s[2d5];int n;{rd(s@n);rsortA(n,s);wt(prev_permutation(s,s+n)&&*s-48?s:"-1");}