A. Distinct Digits ( Codeforces Round #589 (Div. 2) )

You have two integers ll and rr. Find an integer xx which satisfies the conditions below:

  • lxrl≤x≤r.
  • All digits of xx are different.

If there are multiple answers, print any of them.

Input

The first line contains two integers ll and rr (1lr1051≤l≤r≤105).

Output

If an answer exists, print any of them. Otherwise, print 1−1.

Examples
input
Copy
121 130
output
Copy
123
input
Copy
98766 100000
output
Copy
-1
Note

In the first example, 123123 is one of the possible answers. However, 121121 can't be the answer, because there are multiple 11s on different digits.

In the second example, there is no valid answer.

bool judge(lli num)
{
    int a[10]={0};
    while(num)
    {
        if( a[ num%10 ]  )
            return 0;
        else 
            a[ num%10 ] = 1;
        num /= 10;
    }
    return 1;
}
int main()
{
    lli l,r;
    cin>>l>>r;
    for(lli i=l;i<=r;i++)
    {
        if(judge(i)){
            cout<<i<<endl;return 0;
        }
 
    }
    cout<<"-1"<<endl;
 
 
    return 0;
}
所遇皆星河
原文地址:https://www.cnblogs.com/Shallow-dream/p/11650619.html