1. 


/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #146 ID Codes
* Link: http://uva.onlinejudge.org/external/1/146.pdf
*
* @author Schirm , Mathauser , Mohr

* @version 1.0, 06/08/2009
*
* Status : Accepted
* Runtime: 0.084
*/


import java.io.*;
import java.util.Arrays;


public class Main {

public static void main(String[]args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
char[] letters;

while(true){


boolean changed = false;
char tmp;
letters = reader.readLine().toCharArray();
if(letters[0] == '#')
break;

for(int i = letters.length-1; i >= 0; i-- ){
char tmp2 = '|';
int pos = 0 ;
for(int j = letters.length-1; j > i; j--){
if(letters[j] > letters[i] && letters[j]< tmp2){
tmp2 = letters[j];
pos = j;
}
}
if(tmp2 != '|'){
tmp = letters[i];
letters[i] = letters[pos];
letters[pos] = tmp;
changed = true;
Arrays.sort(letters, i+1, letters.length);
break;
}

}
if(!changed)
System.out.println("No Successor");
else
System.out.println(letters);

}

}
}