//next_permutation的运用
#include<bits/stdc++.h> //万能头文件,包含c++所有头文件
using namespace std;
int main()
{
char s[100];
while(scanf("%s",s)==1&&s[0]!='#')
{
int len=strlen(s);
printf("%s\n",next_permutation(s,s+len)?s:"No Successor");
}
return 0;
}