/*
* 给定一个N位的数,返回由这N个数组成的比原来的数大数中的最小的数
*/
#include<cstdio>
#include<string>
#include<stdlib.h>
int cmp(const void*a, const void*b)
{
return *(char*)a - *(char*)b;
}
int main()
{
char str[1024];
int len;
int i, j;
char temp;
int done = 0;
char* ctmp = new char[1024];
ctmp[0] = '/0';
scanf("%s", str);
while(str!="#")
{
len = strlen(str);
for(i=len-1; i>0; i--)
{
for(j=i-1; j>-1; j--)
{
if(str[j]<str[i])
{
temp = str[j];
str[j] = str[i];
str[i] = temp;
done = 1;
break;
}
}
if(done) break;
}
if(i==0)
printf("No Successor/n");
else
{
strcpy(ctmp, &str[j+1]);
str[j+1]='/0';
qsort(ctmp, strlen(ctmp), sizeof(char), cmp);
strcat(str, ctmp);
printf("%s/n", str);
}
scanf("%s", str);
}
return 0;
}