Problem:
Score : 300 points

Problem Statement

Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order.

A word is called diverse if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, atcoder, zscoder and agc are diverse words while gotou and connect aren't diverse words.

Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist.

Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Constraints

1 \leq |S| \leq 26

S is a diverse word.

Input

Input is given from Standard Input in the following format:

S

Output

Print the next word that appears after S in the dictionary, or -1 if it doesn't exist.

Sample Input 1

atcoder

Sample Output 1

atcoderb

atcoderb is the lexicographically smallest diverse word that is lexicographically larger than atcoder. Note that atcoderb is lexicographically smaller than b.

Sample Input 2

abc

Sample Output 2

abcd

Sample Input 3

zyxwvutsrqponmlkjihgfedcba

Sample Output 3

-1

This is the lexicographically largest diverse word, so the answer is -1.

Sample Input 4

abcdefghijklmnopqrstuvwzyx

Sample Output 4

abcdefghijklmnopqrstuvx

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123456
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;

//initialization here
//

//
//initialization finish


// your function is here
//

//
// your function finished

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//

	string s;cin >> s;
	int n = s.size();
	int memo[30];
	rep(i,26) memo[i] = 0;
	

	if(s.size() < 26)
	{
		rep(i,s.size())	memo[(s[i]-'a')] = 1;
		cout << s;
		rep(i,n) if(memo[i] == 0)
		{
			cout << char('a'+ i) << endl;
			return 0;
		}
	}
	else
	{
		int cnt = 25;
		rep(i,n)
		{
			if((s[i]-'a') != cnt) break;
			cnt--;
		}
		if(cnt == -1)
		{
			Print(-1);
			return 0;
		}

		// char('a'+cnt)の文字を変えるとよい
		int pre = s[25]-'a';

		FFOR(i,25,-1)
		{
			if(i == 25)
			{
				pre = s[25] - 'a';
				if(pre == 25)
				{
					cnt = i;
					break;
				}
				continue;
			}

			int now = s[i] - 'a';
			if(pre < now)
			{
				pre = now;
			}else{
				cnt = i+1;
				break;
			}
		}

		string ans = "";
		rep(i,cnt -1) ans += s[i];

		rep(i,ans.size()) memo[ans[i]-'a'] = 1;

		cout << ans;
		FOR(i, s[cnt-1]-'a'+1, n) if(memo[i] == 0)
		{
			cout << char('a'+ i) << endl;
			return 0;
		}


		

	}


	//
	// your code finished


	return 0;
}