You have two integers l and r. Find an integer x which satisfies the conditions below:
l≤x≤r.
All digits of x are different.
If there are multiple answers, print any of them.
Input
The first line contains two integers l and r (1≤l≤r≤105).
Output
If an answer exists, print any of them. Otherwise, print −1.
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
int main()
{
int l,r;
cin>>l>>r;
for(int i=l;i<=r;i++)
{
int x=i;
mp.clear();
while(x)
{
mp[x%10]++;
x/=10;
}
int f=0;
for(int k=0;k<=9;k++) if(mp[k]>1) {f=1;break;}
if(f==0) {cout<<i<<endl;return 0;}
}
cout<<-1<<endl;
}