You have two integers $$$l$$$ and $$$r$$$. Find an integer $$$x$$$ which satisfies the conditions below:  $$$l \le x \le r$$$.  All digits of $$$x$$$ are different. If there are multiple answers, print any of them.

The first line contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^{5}$$$).

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

NoteIn the first example, $$$123$$$ is one of the possible answers. However, $$$121$$$ can't be the answer, because there are multiple $$$1$$$s on different digits.In the second example, there is no valid answer.

#include<stdio.h>
#include<stdlib.h>

int compare(void *pa, void *pb)
{
    int *p1=pa;
    int *p2=pb;
    return *p1-*p2;
}

int main()
{
    int N,M,i,j,k,a,b,c,x,y,s;
    int A[200000];

    scanf("%d %d", &N,&M);

    for(c=N; c<=M; c++)
    {
        x=0;
        i=c;
        while(i>0)
        {
            a=i%10;
            A[x]=a;
            x++;
            i=i/10;
        }
        qsort(A,x,sizeof(int),compare);
        y=0;
        for(j=0; j<(x-1); j++)
        {
            if(A[j]==A[j+1])
            {
                y=1;
                break;
            }
        }
        if(y==0)
        {
            b=c;
            break;
        }
    }

    if(y==0)
    {
        printf("%d\n", b);
    }
    else
    {
        printf("-1\n");
    }

    return 0;
}

#include<stdio.h>
int fun(int n)
{
    int ara[]={1,1,1,1,1,1,1,1,1,1};
    int q=n;
    while(q)
    {
        if(ara[(q%10)]==1)
            ara[q%10]=0;
        else
            return -1;
        q=q/10;
    }
    return n;
}
int main()
{
    int l,r,ans,i;
    scanf("%d%d",&l,&r);
    for(i=l;i<=r;i++)
    {
        ans=fun(i);
        if(ans!=-1)
        {
            printf("%d\n",i);
            break;
        }

    }
    if(i==r+1)
        printf("%d\n",-1);

}

#include <stdio.h>

int dif(int n){
	int arr[10]={0};

	while(n>0){
		if(arr[n%10]>=1){
			return 0;
		}
		arr[n%10]=1;
		n=n/10;
	}
	return 1;
}

int main(){

	int l, r;
	scanf("%d %d", &l, &r);
	int flag=0;
	for(int i=l; i<=r;i++){
		if(dif(i)==1){
			flag=1;
			printf("%d", i);
			break;
		}
	}
	if(flag==0){
		printf("-1\n");
	}

	return 0;
}

#include "stdio.h"
#include "stdbool.h"

bool func(int a) {
	int arr[10];
	int count = 0;
	while (a > 9) {
		int b = a % 10;
		for (int i = 0; i < count; i++) if (arr[i] == b) return false;
		arr[count++] = b;
		a = a / 10;
	}
	int b = a % 10;
	for (int i = 0; i < count; i++) if (arr[i] == b) return false;
	arr[count++] = b;
	return true;
}

int main() {
	int a, b;
	scanf("%i",&a);
	scanf("%i",&b);

	for (int i = a; i <= b; i++) {
		if (func(i)) {
			printf("%i",i);
			return 0;
		}
	}
	printf("-1");
	return 0;
}

#include <stdio.h>

int main(){
    int l, r;
    scanf("%d %d", &l, &r);
    for(int i = l; i <= r; i++){
        int D[10] = { 0 };
        int n = i;
        int f = 0;
        while(n != 0){
            int d = n % 10;
            D[d]++;
            n /= 10;
        }
        for(int j = 0; j < 10; j++){
            if(D[j] > 1) {
                f = 1;
                break;
            }
        }
        if(!f) {
            printf("%d", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

int isLucky(int n)
{
    int arr[15]={};
    for(int i=0;i<10;i++)
        arr[i]=0;
    int num=n;
    while(num>0)
    {
        int digit=num%10;
        if(arr[digit])
            return 0;
        arr[digit]=1;
        num=num/10;
    }
    return 1;
}
int main()
{
    int l,r;
    scanf("%d %d",&l,&r);
    int t=l;
    while(t<=r)
    {
        if(isLucky(t))
        {
            printf("%d",t);
            return 0;
        }
        t++;
    }
    printf("-1");
    return 0;
}

#include <stdio.h>

int distinct(int n) {
	int freq[10] = {0};
	while(n > 0) {
		int index = n % 10;
		if(freq[index] == 1) {
			return 0;
		}
		freq[index] = 1;
		n /= 10;
	}
	return 1;
}

int main() {
	int l, r, result = -1;
	scanf("%d%d", &l, &r);
	while(l <= r) {
		if(distinct(l ++)) {
			result = l - 1;
			break;
		}
	}
	printf("%d", result);
	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,i,k,j,l=0;
    scanf("%d %d",&a,&b);
    char s[100],t;
    for(i=a;i<=b;i++)
    {
        sprintf(s, "%d", i);
        l=0;
        if(strlen(s)>10)
            break;
        for(j=0;j<strlen(s);j++)
        {
            for(k=j+1;k<strlen(s);k++)
            {
                if(s[j]>s[k])
                {
                    t=s[j];
                    s[j]=s[k];
                    s[k]=t;
                }
            }
        }
        for(j=0;j<strlen(s);j++)
        {
            if(s[j]==s[j+1])
            {
                l=0;
                break;
            }
            else l=1;
        }
        if(l==1)
            break;
    }
    if(l==1)
        printf("%d\n",i);
    else printf("-1\n");
    return 0;
}

#include<stdio.h>
#include<string.h>
int solution(int left, int right){
    if(left>right)
        return -1;
    int digit[6];
    int use[10],ruse[10];
    int width;
    memset(digit,0,sizeof(digit));
    memset(use,0,sizeof(use));
    memset(ruse,0,sizeof(ruse));
    int tmpl = left;
    int ret,fdp=-1;
    for(width =0;tmpl>0;width++,tmpl /= 10){
        digit[width]=tmpl%10;
    }
//    for(int i=0;i<6;i++)
//        printf("%d",digit[i]);
    for(int i=width-1;i>=0;i--){
        if(!use[digit[i]])
            use[digit[i]] = 1;
        else
            fdp = fdp>i?fdp:i;
    }
//    printf("fdp=%d \n",fdp);
//    printf("--width=%d---\n",width);
    if(fdp>=0){
        for(int i=width-1;i>fdp;i--)
            ruse[digit[i]] = 1;
//        for(int i=0;i<10;i++)
//            printf("%d",ruse[i]);

        int tmp;
        for(tmp=digit[fdp];tmp<10;tmp++){
            if(!ruse[tmp])
                break;
        }
//        printf("\ntmp=%d\n",tmp);
        if(tmp<10){
            digit[fdp] = tmp;
            ruse[tmp] = 1;
            for(int i=fdp-1;i>=0;i--){
                int min;
                for(min=0;min<10;min++)
                    if(!ruse[min])
                        break;
                digit[i] = min;
                ruse[min] = 1;
//                printf("min=%d",min);
            }
//            printf("--width=%d---\n",width);
//            for(int i=width-1;i>=0;i--)
//                printf("%d",digit[i]);
        }
        else{
            int nz;
            for(nz=fdp+1;;nz++){
                if(nz>=width){
                    width++;
                    break;
                }

                ruse[digit[nz]]=0;
                if(nz>=width)
                    break;
                if(nz<width && (digit[nz]<9 && !ruse[digit[nz]+1]))
                    break;
            }
//            printf("nz=%d\n",nz);
//            for(int i=0;i<nz+1;i++)
//                printf("ruse[%d]=%d\n",i,ruse[i]);
//            printf("digit[nz]=%d\n",digit[nz]);
            digit[nz]++;
            ruse[digit[nz]]=1;
            for(int i=nz-1;i>=0;i--){
                int min;
                for(min=0;min<10;min++)
                    if(!ruse[min])
                        break;
                digit[i] = min;
                ruse[min] = 1;
//                printf("min=%d\n",min);
            }
//            printf("--width=%d---\n",width);
        }
        ret = 0;
        for(int i=width-1;i>=0;i--)
            ret=ret*10+digit[i];
//        printf("ret=%d \n",ret);
    }
    else
        ret = left;
    ret=ret<=right?ret:-1;
    return ret;
}
int main(){
    int left =2234;
    int right = 2343;
    while(~scanf("%d%d",&left,&right)){
        int result=solution(left,right);
        printf("%d\n",result);
    }
    return 0;
}

#include <stdio.h>
#include <math.h>
#include <string.h>
long long arr[10]={0,0,0,0,0,0,0,0,0,0};
int count(long long y)
{
    for(short k=0;k<10;k++)
    arr[k]=0;
    while(y>0)
    {
        arr[(y%10)]++;
        y=y/10;
    }
    for(short k=0;k<10;k++)
    if(arr[k]>1)return 1;
    return 0;
}
int main()
{
    long long x,n,y,l,r;
    short flag=0;
    scanf("%lld %lld",&l,&r);
    for(x=r;x>=l;x--)
    {
        if(count(x)==0)
        {
            printf("%lld",x);
            flag=1;
            break;
        }
    }
    if(flag==0)printf("-1");
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
    long int l,r,i,a[6],rem,j=0,k,n,m,flag;
    scanf("%ld %ld",&l,&r);
    if(1<=l&&l<=r&&r<=100000)
    {
    for(i=l;i<=r;i++)
    {
        j=0;
        rem=i;
        while(rem!=0)
        {

         a[j]=rem%10;
         rem=rem/10;
         j++;
        }
        flag=0;
        for(k=0;k<j;k++)
        {
            for(n=k+1;n<j;n++)
            {
                if(a[k]==a[n])
                {
                  flag=flag+1;

                }

            }
            if(flag!=0)
               break;
        }
        if(flag==0)
        {
            for(m=j-1;m>=0;m--)
               printf("%ld",a[m]);
            exit(0);
        }

    }
    if(flag!=0)
      printf("%ld",-1);
    }
    return 0;
}

#include <stdio.h>

int digits[1000010];

int main()
{
    int l, r;
    scanf("%d %d", &l, &r);

    if (l <= 10)
    {
        printf("%d\n", l);
        return 0;
    }

    for (int i = l; i <= r; i++)
    {
        int j = 0;
        int num = i;

        while (num > 0)
        {
            digits[j] = num % 10;
            j++;
            num /= 10;
        }

        int flag = 0;

        for (int l = 0; l < j; l++)
        {
            for (int k = l + 1; k < j; k++)
            {
                if (digits[l] != digits[k])
                    flag = 1;

                else
                {
                    flag = 0;
                    break;
                }
            }

            if (flag == 0)
                break;
        }

        if (flag == 1)
        {
            printf("%d\n", i);
            return 0;
        }
    }

    printf("-1\n");

    return 0;
}

#include<stdio.h>
int main()
{
    int l,r,i,j,k,sum,num,m,n;
    scanf("%d %d",&l,&r);
    for(i=l;i<=r;i=i+1)
    {
        int count=0,result=0;
        k=i;
        m=i;
       for(j=1;j!=0;j=j+1)
       {
        sum=m%10;
        count=count+1;
        for(n=1;n!=0;n=n+1)
       {
            num=k%10;
            if(sum==num)
            {
                result=result+1;
            }
            k=k/10;
            if(k==0)
            {
                k=i;
                break;
            }
       }
       m=m/10;
       if(m==0)
       {
           break;
       }
       }
       if(result==count)
       {
           printf("%d",i);
           exit(0);

       }
       }
       printf("-1");
    }

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <limits.h>
typedef long long ll;

ll MAX = 100000000000;                      //  1e11
ll MIN = -100000000000;                     // -1e11
ll MOD = 1000000007;

ll longlongmax = __LONG_LONG_MAX__;

ll maxormin(ll a,ll b,ll flag){
    return flag==1?(a>b?a:b):(a<b?a:b);
}

ll overflowcheck(ll a){
    if(a==1){
        return 0;
    }
    else
    {
        ll temp = a;
        ll power = 1;
        while( longlongmax/temp>a ){
            temp *= a;
            power++;
        }
        return power+1;                     // Overflow occurs at this power.
    }

}

ll merge(ll A[],ll B[],ll left,ll mid,ll right){
    ll count = 0;
    ll n1 = mid-left+1;
    ll n2 = right-mid;

    ll LA[n1],LB[n1],RA[n1],RB[n2];

    for(ll n=0;n<n1;n++){ LA[n] = A[n+left];LB[n] = B[n+left];}
    for(ll n=0;n<n2;n++){ RA[n] = A[n+mid+1];RB[n] = B[n+mid+1];}

    ll i=0,j=0,k=left;

    while(i<n1&&j<n2){
        if(LA[i]<RA[j]){
            A[k] = LA[i];
            B[k] = LB[i];
            i++;
        }
        else{
            A[k] = RA[j];
            B[k] = RB[j];
            count += n1-i;
            j++;
        }
        k++;
    }
    while(i<n1){
            A[k] = LA[i];
            B[k] = LB[i];
            i++;
            k++;
    }

    while(j<n2){
            A[k] = RA[j];
            B[k] = RB[j];
            j++;
            k++;
    }
    return count;
}

ll mergesort(ll A[],ll B[],ll left,ll right){
    ll total = 0;
    if(left<right){
        ll mid = (right-left)/2+left;
        total += mergesort(A,B,left,mid);
        total += mergesort(A,B,mid+1,right);
        total += merge(A,B,left,mid,right);
    }
    return total;
}

ll cnt[10];

int main(int argc, char const *argv[])
{
    ll T = 1;
    // scanf("%lld",&T);
    for(ll t = 0; t < T; t++)
    {
        ll l,r;
        scanf("%lld %lld",&l,&r);
        for (ll p = l; p <= r; p++)
        {
            ll r = p;
            ll array[300];
            ll ind = 0;
            while (r)
            {
                cnt[r%10]++;
                r /= 10;
            }
            ll fg = 0;
           for (ll i = 0; i <= 9; i++)
           {
               if(cnt[i]>=2)
               {
                   fg = 1;
               }
           }
           if(!fg)
           {
               printf("%lld\n",p);
            return 0;
           }
           for (ll i = 0; i <= 9; i++)
           {
               cnt[i] = 0;
           }

        }
        printf("-1\n");
    }

    return 0;
}

#include <stdio.h>
int check_digits(long n)
{
	int s[8], i = 0, j, count = 0, total;
	do{
		s[i] = n % 10;
		n = n / 10;
		i++;
	}
	while (n != 0);
	total = i;
	for (i = 0; i < (total - 1); i++ ){
		for (j = i + 1; j < total; j++){
			if (s[i] == s[j]) count++;
		}
	}
	if (count == 0) return 1;
	else return 0;
}
int main()
{
	long a, b, n, i = 0;
	scanf("%ld %ld", &a, &b);
	for (n = a; n <= b; n++){
		if (check_digits(n) == 1) i++;
	}
	if (i == 0) printf("-1");
	else {
		for (n = a; n <= b; n++){
			if (check_digits(n) == 1){
		 	printf("%d ", n);
		  	break;
			}
		}
	}
	return 0;
}

#include <stdio.h>
int unique(int x)
{
    int flag[10] = {};
    while(x)
    {
        int d = x%10;
        if(!flag[d])
            flag[d] = 1;
        else return 0;
        x/=10;
    }
    return 1;
}
int main()
{
    int l,r;
    scanf("%d %d",&l,&r);

    for(int i = l; i <= r ; i++)
        if(unique(i))
        {
            printf("%d",i);
            return 0;
        }
    printf("-1");
    return 0;
}

#include<stdlib.h>
#include<stdlib.h>
int main()
{
    long int l,r,i,ar[6],remi,j=0,k,num,p,count;
    scanf("%ld %ld",&l,&r);
    if(1<=l&&l<=r&&r<=100000)
    {
    for(i=l;i<=r;i++)
    {
        j=0;
        remi=i;
        while(remi!=0)
        {

         ar[j]=remi%10;
         remi=remi/10;
         j++;
        }
        count=0;
        for(k=0;k<j;k++)
        {
            for(num=k+1;num<j;num++)
            {
                if(ar[k]==ar[num])
                {
                  count=count+1;

                }

            }
            if(count!=0)
               break;
        }
        if(count==0)
        {
            for(p=j-1;p>=0;p--)
               printf("%ld",ar[p]);
            exit(0);
        }

    }
    if(count!=0)
      printf("%ld",-1);
    }
}

#include<stdio.h>

int main(void)
{
    int l,r,x,y,digits,m;
    scanf("%d %d",&l,&r);
    x=l;
    while(1)
    {
        digits=0;
        y=x;
        while(y)
        {

            y/=10;
            digits++;

        }

        y=x;
        int a[digits];
        for (int i=0;i<digits;i++)
        {
            a[i]=y%10;
            y/=10;
        }
        for (int i=0;i<digits;i++)
        {
            for (int j=i+1;j<digits;j++)
            {
                if(a[i]!=a[j])
                    {   m=0;
                        continue;
                    }
                else
                    {
                        m=-1;
                        break;
                    }
            }
            if (m==-1)
                break;
        }

        if(m==0 ||  (x>=r && m==-1))
            break;

        else
            x++;

    }
    if(l<10 && r<10)
            printf("%d",l);
    else if (m==-1)
    printf("-1");
    else

        printf("%d",x);
    return 0;
}

#include<stdio.h>

int kt(int n){
	int a[10]={0};
	while(n!=0){
		if(a[n%10]==1)
		return 0;
		else
		a[n%10]=1;
		n/=10;
	}
	return 1;
}
int main(){
	int l,r;
	scanf("%d%d",&l,&r);
	for(int i=l;i<=r;i++){
		if(kt(i)){
			printf("%d",i);
			return 0;
		}
	}
	printf("-1");
	return 0;
}

#include<stdio.h>
int isdifferent(int x)
{
	int a[11],d,val=0,i;
	for(i=0;i<11;i++)
	{
		a[i]=0;
	}
	while(x>0)
	{
		d=x%10;
		x=x/10;
	//	printf("%d\t",d);
		if(a[d]==1)
		{
			val=-1;
		}
		else{
			a[d]=1;
		}
	}
	printf("\n");

	return val;
}
int main()
{
	int l,x,r,i,k=0;
	scanf("%d%d",&l,&r);
	for(i=l;i<=r;i++)
	{
		if(isdifferent(i)==0)
		{
			printf("%d\n",i);
			k++;
			break;
		}
	}
	if(k==0)
	{
		printf("-1\n");
	}
	return 0;
}

#include <stdio.h>

#define fo(i,a,b) for(i=(a);i<=(b);i++)
#define of(i,a,b) for(i=(a);i>=(b);i--)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))

int readInt()
{
   int n;
   scanf("%d", &n);
   return n;
}

int good(int x) {
   int used[10];
   int i;
   fo(i,0,9)used[i]=0;
   while (x) {
      int t = x%10;
      if (used[t]) return 0;
      used[t] = 1;
      x/=10;
   }
   return 1;
}

int main()
{
   int a = readInt();
   int b = readInt();
   int i;
   fo(i,a,b) if (good(i)) {printf("%d\n", i); return 0;}
   printf("-1\n");
   return 0;
}

#include<stdio.h>
int isdis(long long int n)
{
    int a[10],i;
    for( i=0;i<10;i++)
    {
        a[i]=0;
    }

    while(n>0)
    {
        int r=n%10;
        if(a[r])
        {
            return 0;
        }
        else
        {
            a[r]=1;
        }
        n=n/10;

    }
    return 1;
}
int main()
{
    int f=1;
    long long int a,b,val;
    scanf("%lld %lld",&a,&b);
    val=a;
    while(val<=b)
    {
        if(isdis(val))
        {
         f=0;
         break;
        }
        val++;
    }
    if(f==0)
    {
        printf("%lld",val);

    }
    else
    {
        printf("-1");
    }
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int distinct(int n)
{
    int a[10]={0,0,0,0,0,0,0,0,0,0};
    int flag=1;
    while(n>0)
    {
        a[n%10]++;
        if(a[n%10]>1)
        {
            flag=0;
            break;
        }
        n=n/10;
    }
    return flag;
}
int main()
{
    int a, b;
    scanf ("%d %d", &a, &b);
    int flag=1;
    for(int i=a;i<=b;i++)
    {
        if(distinct(i))
        {
            printf("%d",i);
            flag=0;
            break;
        }
    }
    if(flag==1)
        printf("%d",-1);

    return 0;
}

#include<stdio.h>
int isok(int n)
{
        int l=0,i,p=n,a[10]={0};
        while(p>0)
        {
                i=p%10;
                a[i]++;
                p=p/10;

        }
        for(i=0;i<10;i++)
        {
                if(a[i]>1) break;
        }
        if(i==10) return 1;
        else return 0;

}
int main()
{
        int l,r,i;
        scanf("%d%d",&l,&r);
        for(i=l ; i<=r ;i++)
        {
                if( isok(i)==1 )
                {
                        break;
                }
        }
        if(i==r+1) printf("-1\n");
        else printf("%d\n",i);
}

#include<stdio.h>
int fun(int n)
{
    int ara[]={1,1,1,1,1,1,1,1,1,1};
    int q=n;
    while(q)
    {
        if(ara[(q%10)]==1)
            ara[q%10]=0;
        else
            return -1;
        q=q/10;
    }
    return n;
}
int main()
{
    int l,r,ans,i;
    scanf("%d%d",&l,&r);
    for(i=l;i<=r;i++)
    {
        ans=fun(i);
        if(ans!=-1)
        {
            printf("%d\n",i);
            break;
        }

    }
    if(i==r+1)
        printf("%d\n",-1);

}

#include<stdio.h>
int main()
{
    long l,r,i,c=0,j,k,count,a[10],num;
    scanf("%ld %ld",&l,&r);
    for(i=l;i<=r;i++)
    {
        num=i;
        while(i)
        {
            c++;
            i=i/10;
        }
        i=num;
        for(j=0;j<c;j++)
        {
            a[j]=i%10;
            i=i/10;
        }
        count=c;
        for(j=0;j<c-1;j++)
        {
            for(k=j+1;k<c;k++)
            {
                if(a[j]==a[k])
                {
                    count--;
                    break;
                }
            }
        }
        if(c==count)
        {
            printf("%ld",num);
            break;
        }
        c=0;
        i=num;
    }
    if(i>r)printf("-1");
}

#include <stdio.h>

int digit(int n, int ord) {
    for(int i=0;i<ord;i++) {
        n=n/10;
    }
    return n%10;
}

int numl(int n) {
    int k=0;
    while(n!=0) {
        n=n/10;
        k+=1;
    }
    return k;
}

int main(void) {
    int a,b;
    scanf("%d %d", &a, &b);
    for(int i=a;i<=b;i++) {
        int app[10]={};
        int pass=1;
        for(int j=0;j<numl(i);j++) {
            if (app[digit(i,j)]==1) {
                pass=0;
                break;
            }
            app[digit(i,j)]=1;
        }
        if (pass==1) {
            printf("%d", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main() {
    int l, r;
    int true_number = -1;

    scanf("%d%d", &l, &r);

    for(int s = l; s <= r; ++s){
        int vec[10] = {0}, final = 1;
        int len_num = 0, number, num_list[100];
        char result[100], cha[2];

        sprintf(result, "%d", s);
        for(int i = 0; result[i] != '\0'; ++i){
            ++len_num;
            cha[0] = result[i];
            //printf("%s ",cha);
            sscanf(cha, "%d", &number);
            num_list[i] = number;
        }
        //printf("\n");

        for(int i = 0; i < len_num; ++i){
            //printf("%d ",num_list[i]);
            vec[num_list[i]] += 1;
        }
        //printf("\n");

        for(int i = 0; i < 10; ++i){
            if (vec[i] > 1){
                final = 0;
            }
        }
        if (final) {
            true_number = s;
            break;
        }
    }
    printf("%d\n", true_number);

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int isseprate(int x){
    int arr[6]={0};
    int i=0,ans;
    ans=x;
    while(x!=0){
        arr[i++]=x%10;
        x/=10;
    }
    for(int j=0;j<i;j++){
        for(int k=j+1;k<i;k++){
            if(arr[k]==arr[j]){
                return 0;
            }
        }
    }
    printf("%d", ans);
    return 1;
}

int main()
{
   int a,b,flag=0;
   scanf("%d %d", &a,&b);
   for(int i=a;i<=b;i++){
    if(isseprate(i)){
        flag=1;
        break;
    }
   }
   if(flag==0){
    printf("-1");
   }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n, m, i, j, g, u, x;
    char a[100];

    scanf("%d %d", &n, &m);
    u = 0;

    for(i=0; n<=m; i++)
    {
        sprintf(a, "%d", n);
        x = strlen(a);
        for(j=0; j<x-1; j++)
        {
            for(g=j+1; g<x; g++)
            {
                if(a[j]==a[g])
                    goto h;
            }
        }
            if(j==x-1)
            {
                u++;
                goto hh;
            }
        h:
            n = n+1;
    }

    printf("-1");

    hh:
    if(u==1)
        printf("%d", n);
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
	int l,r,i,j,k=0,x,y,count=0,arr[10],flag=0;;
	scanf("%d%d",&l,&r);
	for(i=l;i<=r;i++)
	{
		k=0;
		for(j=i;j>0;j/=10)
		{
			arr[k]=j%10;
			k++;
		}
		count=0;
		for(x=0;x<k;x++)
		{
			for(y=0;y<k;y++)
			{
				if(arr[x]==arr[y])
				count++;
			}
		}
		if(count==k)
			{
				printf("%d",i);
				flag=1;
				exit(0);
			}
	}
	if(flag==0)
	printf("-1");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int myfunction(long int value){
    int mycounter=1;
    bool arr[10];
    for(int i=0;i<10;i++){
        arr[i]=false;
    }
    while (value>0){
        int digit = value%10;
        if(arr[digit]){
            mycounter=0;
            return mycounter;
        }
        arr[digit]=true;
        value=value/10;
    }
    return mycounter;
}

int main(){
    long int l,r;
    scanf("%ld %ld",&l,&r);
    int counter=0,flag=0;
    while(l<=r){
        counter=myfunction(l);
        if(counter==1){
            printf("%ld",l);
            flag=1;
            break;
        }
        else{
            flag=0;
            l++;
        }
    }
    if(flag==0){
        printf("-1");
    }
    return 0;
}

#include <stdio.h>
#include <string.h>
int main(){
    int a,b,c,d,i,j,k,n=0;
    char s[100000];
    scanf("%d%d",&a,&b);
    for(i=a;i<=b;i++)
    {
        sprintf(s,"%d",i);
        int l=strlen(s);
        for(j=0;j<l-1;j++)
        {
            for(k=j+1;k<l;k++)
            {
                if(s[j]==s[k])
                {
                    n++;
                }
            }

        }
        if(n==0)
        {
            break;
        }
       n=0;
    }
    if(i!=b+1)
    {
        printf("%d",i);
    }
    else
    {
        printf("-1");
    }

}

#include <stdio.h>

int main(){
    int l, r;
    scanf("%d %d", &l, &r);
    for(int i = l; i <= r; i++){
        int D[10] = { 0 };
        int n = i;
        int f = 0;
        while(n != 0){
            int d = n % 10;
            D[d]++;
            n /= 10;
        }
        for(int j = 0; j < 10; j++){
            if(D[j] > 1) {
                f = 1;
                break;
            }
        }
        if(!f) {
            printf("%d", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
    int l,r,num,n,f=1,res=-1;
    scanf("%d%d",&l,&r);
    for(int i=l;i<=r&&f==1;i++)
    {
    int g=0,d=0;
    n=i;
    num=i;
    while(n)
    {
    n/=10;
    d++;
    }
    int ar[d];
    for(int x=0;x<d;x++)
   {
    ar[x]=num%10;
    num/=10;
    }
    for(int j=0;j<d-1&&g==0;j++)
    {
    for(int k=j+1;k<d;k++)
    {
    if(ar[j]==ar[k])
   {
    g=1;
    break;
    }
    }
    }
    if(g==0)
    res=i;
    /*else
    res=-1;*/
    }

    printf("%d",res);
    return 0;
}

#include<stdio.h>
#include<math.h>

int khac(int n){
	int a[10]={};
	while(n){
		int r=n%10;
		if(a[r]!=0)
		return 0;
		a[r]=1;
		n/=10;
	}
	return 1;
}
int main(){
	int l,r;
	scanf("%d%d",&l,&r);
	int x=l;
	int a[100];
	while(x<=r){
		if(khac(x)==1){
			printf("%d",x);
			return 0;
		}
		x++;
	}
	printf("-1");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int distinct(int n)
{
    int a[10]={0,0,0,0,0,0,0,0,0,0};
    int flag=1;
    while(n>0)
    {
        a[n%10]++;
        if(a[n%10]>1)
        {
            flag=0;
            break;
        }
        n=n/10;
    }
    return flag;
}
int main()
{
    int a, b;
    scanf ("%d %d", &a, &b);
    int flag=1;
    for(int i=a;i<=b;i++)
    {
        if(distinct(i))
        {
            printf("%d",i);
            break;
            flag=0;
        }
    }
    if(flag)
        printf("%d",-1);

    return 0;
}

#include<stdio.h>
int main()
{
    long int l,r,i,k,j,t,p,count,cot=0,a[100001];
    scanf("%ld%ld",&l,&r);
    for(i=l;i<=r;i++)
    {
        k=i;
        j=0;
        count=0;
        while(k!=0)
        {
            t=k%10;
            k=k/10;
            a[j]=t;
            j++;
        }
        for(k=0;k<j;k++)
        {
            for(p=k+1;p<j;p++)
            {
                if(a[k]==a[p])
                    continue;
                else
                  count++;
            }
        }
        if(count==j)
        {
            printf("%ld",i);
            break;
        }
        else
        {
            cot++;
        }

    }
    if(cot==(r-l)+1)
        printf("-1");
}

#include <stdio.h>

int main(){
    int n, k, passed = 0;
    scanf("%d %d", &n, &k);
    int a[n];

    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        if (a[i] >= k){
            ++passed;
        }
    }
    printf("%d\n", passed);

    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int x = 0, l = 0, r = 0, i, num, j = -1, nj, k;
	int nums[7];
	scanf("%d%d", &l, &r);
	for (i = l; i <= r; i++) {
		int del = 6;
		while (del--)
			nums[del] = -1;
		num = i;
		x = 0;
		while (num >= 1) {
			num /= 10;
			j++;
		}
		nj = j;
		num = i;
		nums[j] = num % 10;
		num /= 10;
		for (j -= 1; j >= 0; j--) {
			nums[j] = num % 10;
			num /= 10;
			for (k = nj; k > j; k--) {
				if (nums[j] == nums[k]) {
					j = -1;
					x--;
				}
			}
			x++;
		}

		if (x == nj) {
			x = i;
			i = r + 1;
		}
	}
	if (i == r + 2)
		printf("%d", x);
	else printf("-1");
	return 0;
}

#include<stdio.h>

int main(void)
{
    int l,r,x,y,digits,m;
    scanf("%d %d",&l,&r);
    x=l;
    while(1)
    {
        digits=0;
        y=x;
        while(y)
        {

            y/=10;
            digits++;

        }

        y=x;
        int a[digits];
        for (int i=0;i<digits;i++)
        {
            a[i]=y%10;
            y/=10;
        }
        for (int i=0;i<digits;i++)
        {
            for (int j=i+1;j<digits;j++)
            {
                if(a[i]!=a[j])
                    {   m=0;
                        continue;
                    }
                else
                    {
                        m=-1;
                        break;
                    }
            }
            if (m==-1)
                break;
        }

        if(m==0 ||  (x>=r && m==-1))
            break;

        else
            x++;

    }

    if (m==-1)
    printf("-1");
    else if(l<10 && r<10)
            printf("%d",l);
    else
        printf("%d",x);
    return 0;
}

#include<stdio.h>

int main(void)
{
    int l,r,x,y,digits,m;
    scanf("%d %d",&l,&r);
    x=l;
    while(1)
    {
        digits=0;
        y=x;
        while(y)
        {

            y/=10;
            digits++;

        }

        y=x;
        int a[digits];
        for (int i=0;i<digits;i++)
        {
            a[i]=y%10;
            y/=10;
        }
        for (int i=0;i<digits;i++)
        {
            for (int j=i+1;j<digits;j++)
            {
                if(a[i]!=a[j])
                    {   m=0;
                        continue;
                    }
                else
                    {
                        m=-1;
                        break;
                    }
            }
            if (m==-1)
                break;
        }

       if(m==0 ||  (x>=r && m==-1))
            break;
        else
            x++;
    }

    if (m==-1)
    printf("-1");
    else
        printf("%d",x);
    return 0;
}

#include<stdio.h>

int main(void)
{
    int l,r,x,y,digits,m;
    scanf("%d %d",&l,&r);
    x=l;
    while(1)
    {
        digits=0;
        y=x;
        while(y)
        {

            y/=10;
            digits++;

        }

        y=x;
        int a[digits];
        for (int i=0;i<digits;i++)
        {
            a[i]=y%10;
            y/=10;
        }
        for (int i=0;i<digits;i++)
        {
            for (int j=i+1;j<digits;j++)
            {
                if(a[i]!=a[j])
                    {   m=0;
                        continue;
                    }
                else
                    {
                        m=-1;
                        break;
                    }
            }
            if (m==-1)
                break;
        }

        if(m==0 || x>r)
            break;
        else
            x++;
    }

    if (m==-1)
    printf("-1");
    else
        printf("%d",x);
    return 0;
}

#include <stdio.h>
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    if(a>b) printf("-1\n");
    else printf("%d\n", a);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main ()
{
    int n,m,i,j,l,r;
    char s[100001],s1[100001];
    char s2[100001];
    scanf("%s%s",&s,&s1);
      m=strlen(s);//printf("%d\n",m);
      int p=strlen(s1);
    l=atoi(s);//printf("%d\n",l);
    r=atoi(s1);//printf("%d\n",r);
    for(i=l;i<=r;i++)
    {
        int c=0;
        int ctr[10]={0};
        snprintf(s2, sizeof(s2), "%d", i);
        //printf("%s\n",s2);
        for(j=0;j<strlen(s2);j++)
        {
            ctr[s2[j]-'0']++;
        }
        for(j=0;j<10;j++)
        {
            //printf("%d\n",ctr[j]);
            if(ctr[j]==1)
                c++;
        }
        //printf("%d c\n",c);
        if(c==m||c==p)
        {printf("%s\n",s2);break;}
        else if(i==r)
        {
            printf("-1\n");break;
        }
    }
  return 0;
}

#include <stdio.h>
#include <math.h>
#include <string.h>
int count(long long y)
{
    long long arr[10]={0};
    while(y>0)
    {
        arr[(y%10)]++;
        y=y/10;
    }
    for(short k=0;k<9;k++)
    if(arr[k]>1)return 1;
    return 0;
}
int main()
{
    long long x,n,y,l,r;
    short flag=0;
    scanf("%lld %lld",&l,&r);
    for(x=r;x>=l;x--)
    {
        if(count(x)==0)
        {
            printf("%lld",x);
            flag=1;
            break;
        }
    }
    if(flag==0)printf("-1");
}

#include <stdio.h>
int a[10]={0};
int is(int i)
{
	int r,p=i,k=0;
	while(i>0)
	{
		r=i%10;
		a[r]=a[r]+1;
		if(a[r]>1)
		{
			return 0;
		}
		i=i/10;
	}
	return 1;

}
int main()
{
	int l,r,p=0;
	scanf("%d %d",&l,&r);
	for(int i=l;i<=r;i++)
	{
		if(is(i))
		{
			printf("%d\n",i);
			p=1;
			break;
		}
	}
	if(p==0)
	{
		printf("-1\n");
	}
	return 0;
}

#include <stdio.h>
int main(void) {
    int x,l,r,c=0,copy,copy1,d=0;
    scanf("%d %d",&l,&r);
    for(x=l;x<=r;x++)
    {
        copy1=x;c=0,d=0;
        while(copy1)
        {
        copy=x;
        while(copy){
            if(copy%10==copy1%10)
            {
                c++;

            }
                copy/=10;

        }
        copy1/=10;d++;
        }

        if(c==d)        {
            printf("%d",x);
            break;
        }

    }
	// your code goes here
	return 0;
}

#include<stdio.h>
#include<string.h>

_Bool different(int x){
	int nums[10];
	memset(nums, 0, sizeof(nums));
	while(x){
		if(nums[x%10]) return 0;
		nums[x%10]=1;
		x/=10;
	}
	return 1;
}

int main(){
	int l, r, x;
	scanf("%d %d", &l, &r);
	for(x=l+1;x<r;++x){
		if(different(x)){
			printf("%d\n", x);
			return 0;
		}
	}
	puts("-1");
	return 0;
}

#include<stdio.h>
int main()
{
    long l,r,i,c=0,j,k,count,a[10],num;
    scanf("%ld %ld",&l,&r);
    for(i=l+1;i<r;i++)
    {
        num=i;
        while(i)
        {
            c++;
            i=i/10;
        }
        i=num;
        for(j=0;j<c;j++)
        {
            a[j]=i%10;
            i=i/10;
        }
        count=c;
        for(j=0;j<c-1;j++)
        {
            for(k=j+1;k<c;k++)
            {
                if(a[j]==a[k])
                {
                    count--;
                    break;
                }
            }
        }
        if(c==count)
        {
            printf("%ld",num);
            break;
        }
        c=0;
        i=num;
    }
    if(i==r)printf("-1");
}

#include <stdio.h>

int main(){
    int l, r;
    scanf("%d %d", &l, &r);
    for(int i = l + 1; i < r; i++){
        int D[10] = { 0 };
        int n = i;
        int f = 0;
        while(n != 0){
            int d = n % 10;
            D[d]++;
            n /= 10;
        }
        for(int j = 0; j < 10; j++){
            if(D[j] > 1) {
                f = 1;
                break;
            }
        }
        if(!f) {
            printf("%d", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

#include<stdio.h>
int main()
{
	long long int l,r,i,temp,j,rem,n,k,flag;
	scanf("%lld %lld",&l,&r);
	for(i=l;i<r;i++)
	{
		flag=0;
		temp=i;
		l=0;
		long long int f[100000];
		while(temp>0)
		{
			rem=temp%10;
			f[l]=rem;
			l++;
			temp=temp/10;
		}
		int e1=0;
		for(j=0;j<l;j++)
		{
			for(k=j+1;k<l;k++)
			{
				if(f[j]==f[k])
				{
					e1++;
				}
			}
		}
		if(e1==0)
		{
			printf("%d",i);
			goto end;
		}
		else
		{
			flag=1;
		}
	}
	if(flag==1)
	{
		printf("-1");
	}
	end:
		printf("");
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n, m, i, j, g, u, x;
    char a[100];

    scanf("%d %d", &n, &m);
    u = 0;
    for(i=0; n<=m; i++)
    {
        sprintf(a, "%d", n);
        x = strlen(a);
        for(j=0; j<x-1; j++)
        {
            for(g=j+1; g<x; g++)
            {
                if(a[j]==a[g])
                    goto h;
            }
            if(j==x-2)
            {
                u++;
                goto hh;
            }

        }

        h:
            n = n+1;
    }

    printf("-1");

    hh:
    if(u==1)
        printf("%d", n);

}

#include <stdio.h>
#include <stdbool.h>

bool findnum(int x){
	unsigned long int freq[10],i;
	int count,digits;
	for(i=0;i<10;i++){
	  freq[i]=0;
	}
	digits=0;
	while(x!=0){
	  freq[x%10]++;
	  x/=10;
	  digits++;
	}
	count=0;
	for(i=0;i<10;i++){
	  if(freq[i]!=0){
	  	count++;
	  }
	}
	if(digits==count){
		return true;
	}
	else{
		return false;
	}
}

int main(void){
	unsigned long int l,x,r;
	scanf("%lu%lu",&l,&r);
	for(x=l;x<=r;x++){
	  if(findnum(x)==true){
	  	printf("%lu",x);
	  	break;
	  }
	}
	if(x=r&&findnum(x)==false){
	  printf("%d",-1);
	}
	return 0;
}

#include <stdio.h>
#include <stdbool.h>

bool findnum(int x){
	unsigned long int freq[10],i;
	int count,digits;
	for(i=0;i<10;i++){
	  freq[i]=0;
	}
	digits=0;
	while(x!=0){
	  freq[x%10]++;
	  x/=10;
	  digits++;
	}
	count=0;
	for(i=0;i<10;i++){
	  if(freq[i]!=0){
	  	count++;
	  }
	}
	if(digits==count){
		return true;
	}
	else{
		return false;
	}
}

int main(void){
	unsigned long int l,x,r;
	scanf("%lu%lu",&l,&r);
	for(x=l;x<=r;x++){
	  if(findnum(x)==true){
	  	printf("%lu",x);
	  	break;
	  }
	}
	if(x==r&&findnum(x)==false){
	  printf("%d",-1);
	}
	return 0;
}

#include<stdio.h>
int fun(int n)
{
    int ara[]={1,1,1,1,1,1,1,1,1,1};
    int q=n,i;
    while(q)
    {
        if(ara[(q%10)-1]==1)
            ara[q%10-1]=0;
        else
            return -1;
        q=q/10;
    }
    return n;
}
int main()
{
    int l,r,ans,i;
    scanf("%d%d",&l,&r);
    for(i=l;i<=r;i++)
    {
        ans=fun(i);
        if(ans!=-1)
        {
            printf("%d\n",i);
            break;
        }

    }
    if(i==r+1)
        printf("%d\n",-1);

}

#include <stdio.h>
int check_digits(long n)
{
	int s[8], i = 0, j, count = 0, total;
	do{
		s[i] = n % 10;
		n = n / 10;
		i++;
	}
	while (n != 0);
	total = i;
	for (i = 0; i < (total - 1); i++ ){
		for (j = i + 1; j < total; j++){
			if (s[i] == s[j]) count++;
		}
	}
	if (count == 0) return 1;
	else return 0;
}
int main()
{
	long a, b, n, i = 0;
	scanf("%ld %ld", &a, &b);
	for (n = a; n <= b; n++){
		if (check_digits(n) == 1) i++;
	}
	if (i == 0) printf("-1");
	else {
		for (n = a; n <= b; n++){
		if (check_digits(n) == 1) printf("%d ", n);
	}
	}
	return 0;
}

#include<stdio.h>
int main()
{
    int l,r,i,j,k,count=0,result=0,sum,num,m,n;
    scanf("%d %d",&l,&r);
    for(i=l;i<=r;i=i+1)
    {
        k=i;
        m=i;
        for(j=1;j!=0;j=j+1)
       {
           if(i>=10)
           {
            sum=i%10;

           i=(i/10);
           count=count+1;
           }
           else if(i<10)
           {
               break;
           }
        }
       for(j=1;j<=(count+1);j=j+1)
       {
        sum=m%10;
        for(n=1;n<=(count+1);n=n+1)
       {
            num=k%10;
            if(sum==num)
            {
                result=result+1;
            }
            num=(k/10);
            k=k/10;
       }
       sum=(m/10);
       m=m/10;
       if(result>(count+1))
       {
           break;
       }
       else if(result==(count+1))
       {
           printf("%d",i);
           exit(0);

       }
       }
    }
}

#include <stdio.h>

int digits[1000010];

int main()
{
    int l, r;
    scanf("%d %d", &l, &r);

    for (int i = l; i <= r; i++)
    {
        int j = 0;
        int num = i;

        while (num > 0)
        {
            digits[j] = num % 10;
            j++;
            num /= 10;
        }

        int flag = 0;

        for (int l = 0; l < j; l++)
        {
            for (int k = l + 1; k < j; k++)
            {
                if (digits[l] != digits[k])
                    flag = 1;

                else
                {
                    flag = 0;
                    break;
                }
            }

            if (flag == 0)
                break;
        }

        if (flag == 1)
        {
            printf("%d\n", i);
            return 0;
        }
    }

    printf("-1\n");

    return 0;
}

#include <stdio.h>

int digits[100010];

int main()
{
    int l, r;
    scanf("%d %d", &l, &r);

    for (int i = l; i <= r; i++)
    {
        int j = 0;
        int num = i;

        while (num > 0)
        {
            digits[j] = num % 10;
            j++;
            num /= 10;
        }

        int flag = 0;

        for (int l = 0; l < j; l++)
        {
            for (int k = l + 1; k < j; k++)
            {
                if (digits[l] != digits[k])
                    flag = 1;

                else
                {
                    flag = 0;
                    break;
                }
            }

            if (flag == 0)
                break;
        }

        if (flag == 1)
        {
            printf("%d\n", i);
            return 0;
        }
    }

    printf("-1\n");

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
 int l,r,i,j,c=0,*a,t,f,n,x;
 printf("Enter two number range");
 scanf("%d%d",&l,&r);
 i=r;
 while(i>0)
 {
  c++;
  i=i/10;
 }
 a=(int*)malloc(c*sizeof(int));
 for(n=l;n<r;n++)
 {
  for(i=0;i<c;i++)
   *(a+i)=-1;
  i=n;
  t=0;
  f=0;
  while(i>0)
  {
   x=i%10;
   i=i/10;
   for(j=0;j<t;j++)
   {
    if(x==*(a+j))
    {
     f=1;
     break;
	}
   }
   if(f!=1)
   {
    *(a+t)=x;
    t++;
   }
  }
  if(i<=0&&f==0)
  {
   printf("\n%d",n);
   break;
  }
  fflush(stdin);
 }
 if(n==r)
  printf("-1");
 free(a);
return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    long long int l,r,i,j,k,c,f;
    scanf("%lld %lld",&l,&r);
    for(i=l+1;i<=r;i++)
    {
        long long int a[100]={0}, k=i; f=0;
        while(k>0)
        {
            a[k%10]++;
            k=k/10;
        }
        for(j=0;j<10;j++)
        { //printf("%lld ",a[j]);
            if(a[j]>1)
            f=1;
        }
        if(f==0) { printf("%lld",i); break;}
    }
    if(f==1) printf("-1");
}

#include<stdio.h>
#include<string.h>
int main()
{
    long long int l,r,i,j,k,c,f;
    scanf("%lld %lld",&l,&r);
    if(l==r)
    { long long int a[100]={0};
        while(r>0)
        {
            a[r%10]++; r=r/10;
        }
         for(j=0;j<10;j++)
        { //printf("%lld ",a[j]);
            if(a[j]>1)
            f=1;
        }
        if(f==0) { printf("%lld",i); }
        else printf("%lld",l);
    }
    else for(i=l+1;i<=r;i++)
    {
        long long int a[100]={0}, k=i; f=0;
        while(k>0)
        {
            a[k%10]++;
            k=k/10;
        }
        for(j=0;j<10;j++)
        { //printf("%lld ",a[j]);
            if(a[j]>1)
            f=1;
        }
        if(f==0) { printf("%lld",i); break;}
    }
    if(f==1) printf("-1");
}

#include<stdio.h>
#include<string.h>
int main()
{
    long long int l,r,i,j,k,c,f;
    scanf("%lld %lld",&l,&r);
    if(l==r) printf("%lld",l);
    else for(i=l+1;i<=r;i++)
    {
        long long int a[100]={0}, k=i; f=0;
        while(k>0)
        {
            a[k%10]++;
            k=k/10;
        }
        for(j=0;j<10;j++)
        { //printf("%lld ",a[j]);
            if(a[j]>1)
            f=1;
        }
        if(f==0) { printf("%lld",i); break;}
    }
    if(f==1) printf("-1");
}

int isLucky(int n)
{
    int arr[10]={};
    for(int i=0;i<10;i++)
        arr[i]=0;
    int num=n;
    while(num>0)
    {
        int digit=num%10;
        if(arr[digit])
            return 0;
        arr[digit]=1;
        num=num/10;
    }
    return 1;
}
int main()
{
    int l,r;
    scanf("%d %d",&l,&r);
    int t=l-1;
    while(t<=r)
    {
        t=t+1;
        if(isLucky(t))
        {
            printf("%d",t);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

int isLucky(int n)
{
    int arr[15]={};
    for(int i=0;i<10;i++)
        arr[i]=0;
    int num=n;
    while(num>0)
    {
        int digit=num%10;
        if(arr[digit])
            return 0;
        arr[digit]=1;
        num=num/10;
    }
    return 1;
}
int main()
{
    int l,r;
    scanf("%d %d",&l,&r);
    int t=l-1;
    while(t<=r)
    {
        t=t+1;
        if(isLucky(t))
        {
            printf("%d",t);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

#include<stdio.h>
int main()
{
      int l,r,ans,a[6];
      scanf("%d %d",&l,&r);
      int i;
      for( i=l;i<r;i++)
      {int j=i;int k=0;
            while(j)
            {
                  a[k]=j%10;
                  j/=10;
                  k++;
            }
            while(k--)
            {
                  if(a[k]==a[k-1])
                  break;
            }
            if(k==0) ans=i;

      }
      if(i==r) printf("-1\n");
      else printf("%d\n",ans);

}

#include<stdio.h>
int main()
{
      int l,r,ans,a[6];
      scanf("%d %d",&l,&r);
      int i;
      for( i=l+1;i<r;i++)
      {int j=i;int k=0;int flag=1;
            while(j)
            {
                  a[k]=j%10;
                  j/=10;
                  k++;
            }
            int t;
           for(t=0;t<k;t++)
           {
            for(int p=t+1;p<k;p++)
            {
                  if(a[t]==a[p]) {
                        flag=0;
                        break;

                  }
            }
            if(flag==0)
                  break;
           }
            if(t==k) {ans=i;break;}

      }
      if(i==r) printf("-1\n");
      else printf("%d\n",ans);

}

#include<stdio.h>
int main()
{
      int l,r,ans,a[6];
      scanf("%d %d",&l,&r);
      int i;
      for( i=l;i<r;i++)
      {int j=i;int k=0;
            while(j)
            {
                  a[k]=j%10;
                  j/=10;
                  k++;
            }
            k=k-1;
            while(k)
            {
                  if(a[k]==a[k-1])
                  break;
            k--;
            }
            if(k==0) {ans=i;break;}

      }
      if(i==r) printf("-1\n");
      else printf("%d\n",ans);

}

#include<stdio.h>
int main()
{
      int l,r,ans,a[6];
      scanf("%d %d",&l,&r);
      int i;
      for( i=l+1;i<r;i++)
      {int j=i;int k=0;
            while(j)
            {
                  a[k]=j%10;
                  j/=10;
                  k++;
            }
            k=k-1;
            while(k)
            {
                  if(a[k]==a[k-1])
                  break;
            k--;
            }
            if(k==0) {ans=i;break;}

      }
      if(i==r) printf("-1\n");
      else printf("%d\n",ans);

}

/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>

int isdistinct(int l)
{
    int len=0,i,j,arr[10]={0};
    while(l!=0)
    {
        arr[len++]=l%10;
        l=l/10;
    }
    for(i=0;i<len-1;i++)
    {
        for(j=i+1;j<len;j++)
        {
            if(arr[i]==arr[j]) return 0;
        }
    }
    return 1;

}

int main()
{
  int T,l,r,flag;
  scanf("%d",&T);
  while(T--)
  {
      scanf("%d",&l);
      scanf("%d",&r);
      flag=0;
      while(l<=r)
      {
          if(isdistinct(l))
          {
              printf("%d\n",l);
              flag=1;
              break;
          }
          else l++;
      }
      if(flag==0) printf("-1\n");
  }
 return 0;
}

/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>

int isdistinct(int l)
{
    int len=0,i,j,arr[10]={0};
    while(l!=0)
    {
        arr[len++]=l%10;
        l=l/10;
    }
    for(i=0;i<len-1;i++)
    {
        for(j=i+1;j<len;j++)
        {
            if(arr[i]==arr[j]) return 0;
        }
    }
    return 1;

}

int main()
{
  int T,l,r,flag;
  scanf("%d",&T);
      scanf("%d",&l);
      scanf("%d",&r);
      flag=0;
      while(l<=r)
      {
          if(isdistinct(l))
          {
              printf("%d\n",l);
              flag=1;
              break;
          }
          else l++;
      }
      if(flag==0) printf("-1\n");
 return 0;
}

#include<stdio.h>
int main()
{
    long int l,x,r,i,num,no;
    int c=0,check=1,li=0,ab=-1,j=0,a[6],k;
    scanf("%ld %ld",&l,&x);
    for(i=l;i<=x;i++)
    {
        check=1;
         no=i;
         num=i;
        while(no!=0)
        {
            a[j]=no%10;
            no=no/10;
            c++;
            j++;
        }
        for(j=0;j<c-1;j++)
        {
            for(k=j+1;k<c;k++){

            if(a[j]==a[k])
            {
                check=0;
                break;
            }}
            if(check==0)
                break;
        }
        if(check==1)
        {
            printf("%ld",i);
            li=1;
            break;
        }
    }
    if(li==0)
    {
        printf("%d",ab);
    }
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
    int l,r,num,n,f=1,res;
    scanf("%d%d",&l,&r);
    for(int i=l;i<=r&&f==1;i++)
    {
    int g=0,d=0;
    n=i;
    num=i;
    while(n)
    {
    n/=10;
    d++;
    }
    int ar[d];
    for(int x=0;x<d;x++)
   {
    ar[x]=num%10;
    num/=10;
    }
    for(int j=0;j<d-1&&g==0;j++)
    {
    for(int k=j+1;k<d;k++)
    {
    if(ar[j]==ar[k])
   {
    g=1;
    break;
    }
    }
    }
    if(g==0)
    res=i;
    else
    res=-1;
    }

    printf("%d",res);
    return 0;
}

#include<stdio.h>

int main()
{
    int l,r,d=0,n,res=0,num=0;
    scanf("%d%d",&l,&r);
    n=l;
    while(n)
    {
    n/=10;
    d++;
    }
    num=l/(pow(10,d-1));
    for(int i=d-1;i>=0;i--)
    {
    res+=(pow(10,i))*num;
    num++;
    }
    if(res<=r)
    printf("%d",res);
    else
    printf("%d",-1);
    return 0;
}

#include<stdio.h>

int main ()
{
	int l,r,temp,k;

	scanf("%d %d",&l, &r);

	int flag=1;

	for ( int i=l ; (i<=r)&&(flag!=0) ; i++ )
	{
		int dig[10]={0};

		temp=i;
		flag=0;

		while (temp)
		{
			if (dig[temp%10]==0)
			{
				dig[temp%10]++;
			}

			else
				flag++;

			temp=temp/10;
		}

		k=i;
	}

	if (k==r)
		printf("-1\n");

	else
		printf("%d\n", k);

	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,i,n,k,j,l=0;
    char A[200];
    scanf("%d %d",&a,&b);
    for(i=a;i<b;i++)
    {
        sprintf(A,"%d",i);
        for(j=0;j<strlen(A);j++)
        {
            for(k=j+1;k<strlen(A);k++)
            {
                if(A[j]==A[k])
                    {
                        l=0;
                        break;
                    }
                    else l=1;
            }
        }
        if(l==1)
            break;
    }
    if(l==1)
        printf("%d\n",i);
    else printf("-1\n");
    return 0;
}