// Working program using Reader Class
import java.io.*;
import java.util.*;

public class Main
{
	static class Reader
	{
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader()
		{
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException
		{
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException
		{
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1)
			{
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException
		{
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
			{
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException
		{
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException
		{
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');

			if (c == '.')
			{
				while ((c = read()) >= '0' && c <= '9')
				{
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException
		{
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException
		{
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException
		{
			if (din == null)
				return;
			din.close();
		}
	}

	public static void main(String[] args) throws IOException
	{
		Reader sc = new Reader();
		int l = sc.nextInt();
		int r = sc.nextInt();
		String s1 = "";
		while (l <= r) {
			Set<Character> set = new HashSet<Character>();
			StringBuilder s = new StringBuilder(String.valueOf(l));
			for (int i = 0; i < s.length(); i++) {
				set.add(s.charAt(i));
			}
			//System.out.println(set);
			if (set.size() == s.length()) {
			    s1 = s.toString();
				break;
			}
			l++;
		}
		if (s1.length() == 0) {
		    System.out.println(-1);
		}
		else {
		    System.out.println(s1);
		}
	}
}

import java.util.Scanner;

public class Distinct_Digits {
    public static boolean check(int a) {
        int[] digits = new int[100];
        int count = 0;
        while (a > 0) {
            count++;
            digits[count] = a % 10;
            a /= 10;
        }
        for (int i = 1; i < count ; i++) {
            for (int j = i+1; j <= count ; j++) {
                if (digits[i] == digits[j]) return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int L = scanner.nextInt();
        int R = scanner.nextInt();
        boolean chk = false;
        for (int i = L; i <= R ; i++) {
            if (check(i)) {
                System.out.println(i);
                chk = true;
                break;
            }
        }
        if (chk == false)
            System.out.println(-1);

    }
}

import java.util.*;
public class Main {
    ArrayList<Integer> Arr=new ArrayList<Integer>();
	Main(){
		for(int i=0;i<10;i++) {
			Arr.add(0);
		}
	}
	public boolean check(int n) {
		ArrayList<Integer> a= (ArrayList<Integer>)Arr.clone();
		while(n>0) {
			if(a.get(n%10)==1) {return false;}
			a.set(n%10,1);
			n=n/10;
		}
		return true;

	}

	public static void main(String[]agrs) {
		Main obj=new Main();
	    Scanner input=new Scanner(System.in);
	    int l,r;
	     l=input.nextInt();
	     r=input.nextInt();
	     for(int x=l;x<=r;x++) {
	    	 if(obj.check(x)) {
	    		 System.out.print(x);
	    		 return;
	    	 }
	     }
	     System.out.print("-1");

	}
}

import javax.print.DocFlavor;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Q121
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        boolean res = false;
        for(Integer i = a; i <= b; i++)
        {
            if(isDistinct(i))
            {
                System.out.println(i);
                res = true;
                break;
            }
        }
        if(!res)
        {
            System.out.println("-1");
        }

    }

    private static boolean isDistinct(Integer a)
    {
        String str = a.toString();
        Set<Character>characterSet = new HashSet<Character>();
        for(int i = 0; i < str.length(); i++)
            characterSet.add(str.charAt(i));
        return characterSet.size() == str.length();
    }
}

// import java.io.*;
// import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// import java.util.Scanner;
import java.util.StringTokenizer;

public class distinctDigit
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)
    {
        FastReader in = new FastReader();
        int l = in.nextInt();
        int r = in.nextInt();
        int f=0;
        for (int i=l ; i<=r ; i++)
        {
            int num = i;
            boolean visited[] = new boolean[100];
            while (num != 0)
            {
                if (visited[num % 10])
                    break;

                visited[num%10] = true;

                num = num/10;
            }
            if (num == 0){
                f=1;
                System.out.print(i);
                break;
            }
        }
        if(f==0) {System.out.println(-1);}
    }
}

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt();
        int res=-1;
        for(int i=a;i<=b;i++){
            if(good(i)){
                res=i;
                break;
            }
        }
        System.out.println(res);
    }

    public static boolean good(int n){
        String s=Integer.toString(n);
        int []a=new int[10];
        for(int i=0;i<s.length();i++){
            a[(int)s.charAt(i)-48]++;
        }
        for(int i:a){
            if(i>1)
            return false;
        }
        return true;
    }
}

/**
 * @author Juan Sebastian Beltran Rojas
 * @mail jsbeltran.valhalla@gmail.com
 * @veredict
 * @url https://codeforces.com/problemset/problem/1228/A
 * @category adhoc
 * @date 30/09/2019
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CF1228A {
    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        for (String ln; (ln = in.readLine()) != null; ) {
            StringTokenizer st = new StringTokenizer(ln);
            int a = parseInt(st.nextToken()), b = parseInt(st.nextToken());
            boolean ws = false;
            for (int i = a; i <= b; i++)
                if (check(i)) {
                    System.out.println(i);
                    ws = true;
                    break;
                }
            if (!ws) System.out.println(-1);
        }
    }

    private static boolean check(int a) {
        boolean[] v = new boolean[10];
        for (; a > 0; a /= 10)
            if (v[a % 10]) return false;
            else v[a % 10] = true;
        return true;
    }
}

import java.io.*;
import java.util.*;
public class Main{
    public static void main(String args[])throws IOException
    {
        BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
        String temp[]=obj.readLine().split(" ");
        int l=Integer.parseInt(temp[0]);
        int r=Integer.parseInt(temp[1]);
        if(Integer.parseInt(temp[0])<1 ||Integer.parseInt(temp[0])>100000)
        {System.out.println(-1);
            return;
        }

        if(Integer.parseInt(temp[1])<1 ||Integer.parseInt(temp[1])>100000)
        {System.out.println(-1);
            return;
        }

        HashSet<Character> set=new HashSet<>();
        for(int i=l;i<=r;i++)
        {
            String str=Integer.toString(i);
            set.clear();
            for(int j=0;j<str.length();j++)
            {
                if(set.contains(str.charAt(j)))
                {
                    set.clear();
                    break;
                }
                else
                {
                    set.add(str.charAt(j));
                }
            }
            if(set.size()==str.length())
            {
                System.out.println(str);
                return;
            }
        }
        System.out.println(-1);

    }
}

import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Round582_Div2_A_DistinctDigits {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int firstInt = inp.nextInt();
            int secondInt = inp.nextInt();

            for(int i = firstInt; i <= secondInt; i++) {
                if(checkDistinctDigits(i)) {
                    System.out.println(i);
                    System.exit(0);
                }
            }
            System.out.println("-1");
        }
    }

    public static boolean checkDistinctDigits(int x) {
        String[] splitX = String.valueOf(x).split("");
        ArrayList<Integer> checkList = new ArrayList<>();
        for (String y: splitX) {
            if(checkList.contains(Integer.valueOf(y))) return false;
            else checkList.add(Integer.valueOf(y));
        }
        return true;
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}

import java.util.HashSet;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {

		//Input de consola

		Scanner sc = new Scanner(System.in);

		String[] s =sc.nextLine().split(" ");
		int l = Integer.parseInt(s[0]);
		int r = Integer.parseInt(s[1]);

		//Programa

		HashSet<String> hs;
		boolean found = false;

		for(int i=l; i<=r; i++) {
			hs = new HashSet<String>();
			s = String.valueOf(i).split("");
			for(int j=0; j<s.length; j++) {
				hs.add(s[j]);
			}
			if(hs.size()==s.length) {
				System.out.println(i);
				found = true;
				break;
			}
		}

		if(!found) {
			System.out.println(-1);
		}

	}

}

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {

     Scanner input = new Scanner(System.in);
     int l = input.nextInt();
     int r = input.nextInt();

     while(l <= r){
         boolean [] taken = new boolean[10];
         boolean ok = true;
         String s = l + "";
         //Check
         for(int i = 0 ; i < s.length() ; i++)
             if(!taken[Integer.parseInt(s.charAt(i) + "")])
                  taken[Integer.parseInt(s.charAt(i) + "")] = true;
             else{
                 ok = false;
                 break;
             }

           if(ok){
               System.out.println(l);
               System.exit(0);
            }
           l++;
           }
             System.out.println(-1);
    }
}

import java.util.*;

public class A {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r,i,a,b,x;

		a=sc.nextInt();
		b=sc.nextInt();

		for(i=a;i<=b;i++) {
			int sig=0;
			int d[] = new int[10];
			x=i;
			while(x>0)
			{
				r = x%10;
				d[r] = d[r] + 1;
				if(d[r]>1)
				{
					sig  = 1;
					break;
				}
				x=x/10;
			}
			if(sig==0)
			{
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
}

//import java.io.*;
import java.util.*;
public class Hello {
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
		while(l<=r) {
			if(check(l)) {
				System.out.println(l);
				return;
			}
			l++;
		}
		System.out.println(-1);
	}
	public static boolean check(int n) {
		boolean a[] = new boolean[10];
		while(n>0) {
			if(a[n%10]) return false;
			a[n%10] = true;
			n = n/10;
		}
		return true;
	}
}

import java.util.*;
import java.math.*;

public class DistinctDigits{

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int l = sc.nextInt(), r = sc.nextInt();
	boolean foo = false;

	while(l <= r){
		int num = l;
		Set<Integer> set = new HashSet<>();

		while(num > 0){
			int x = num%10;
			num = num/10;
			set.add(x);
		}
		if(set.size() == (int)(Math.log10(l)+1)){
			foo = true;
			break;
		}
		l++;
	}
	if(foo)
		System.out.println(l);
	else
		System.out.println(-1);
}
}

import java.util.Scanner;

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        boolean hello = false;
        for (int i = a; i <=b ; i++) {
            Integer check = i;
            String string = check.toString();
            boolean flag = false;
            for (int j = 0; j < string.length()-1; j++) {
                for (int k = j+1; k < string.length(); k++) {
                    if(string.charAt(j)==string.charAt(k)){
                        flag = true;
                    }
                }
            }
            if(!flag){
                System.out.println(string);
                hello = true;
                break;
            }

        }
        if(!hello){
            System.out.println(-1);
        }
    }
}

import java.util.Scanner;

public class Main {

    static boolean isDiff(int n)
    {

        boolean arr[]=new boolean[10];
        for (int i = 0; i < 10; i++)
            arr[i] = false;

        while (n > 0)
        {
            int digit = n % 10;

            if (arr[digit])
                return false;

            arr[digit] = true;

            n = n / 10;
        }
        return true;
    }

    public static void main (String[] args)
    {
        int l, x = -1, r;

        boolean status = false;

        Scanner scanner = new Scanner(System.in);
        l = scanner.nextInt();
        r = scanner.nextInt();

        if(1<=l && l <= r)
        {
            if(l<=r && r<= 100000){
                for (int i = l; i <= r; i++){
                    if(isDiff(i)){
                        status = true;
                        x = i;
                        break;
                    }
                    else {
                        status = false;
                    }
                }
            }
        }

        if(status){
            System.out.print(x);
        }
        else{
            System.out.print("-1");
        }

    }
}

import java.util.Scanner;import java.util.Arrays;
public class digit {
	public static boolean dool (int a) {
		int l = (int) Math.log10(a) + 1;
		int []d; d=new int [l];
		for (int i = 0; i < l; i++) {
			d[i] = a % 10;
			a /= 10;
		}
		Arrays.sort(d);
		boolean kir = true;
		for (int i = 1; i < l; i++) {
			if (d[i]==d[i-1]) kir=false;
		}
		if (kir==true) return true;
		else return false;
	}
public static void main (String [] args) {
Scanner scanner = new Scanner (System.in);
int r = scanner.nextInt();
int x = scanner.nextInt();
boolean chool=false;
int u=0;
for(int i=r;i<=x;i++){
	if (dool(i)==true) {
		chool=true;
		u=i;
		break;
		}
}
if (chool==true) System.out.println(u);
else System.out.println(-1);
scanner.close(); }}

import java.util.ArrayList;
import java.util.Scanner;

public class distinct_digits {
    public static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        boolean t = false;

        while(!t){
            int k = n;
            ArrayList<Integer> arr = new ArrayList<>();
            t = true;
            while(k>0){
                int r = k%10;
                if(arr.contains(r)){
                    t = false;
                    break;
                } else {
                    arr.add(r);
                }
                k = (int) k/10;
            }

            if (t){
                System.out.println(n);
                break;
            } else if (n+1 <= m){
                n++;
            } else {
                System.out.println(-1);
                break;
            }
        }
    }

}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import static java.lang.Math.abs;
import java.util.Scanner;

/**
 *
 * @author pranto
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in=new Scanner(System.in);
        int l=in.nextInt();
        int r=in.nextInt();
        boolean flag=true;
        if(l>=1 && r>=1 && l<=100000 && r<=100000){
        for (int i=l;i<=r;i++) {

        int num = i;
        boolean visited[]=new  boolean[10];

        while (num!=0)
        {

            if (visited[num % 10]) {

                break; }

            visited[num%10] = true;

            num = num/10;
        }

        if(num==0)
        {
            System.out.println(i);
            flag=false;
            break;
        }

        }}
        if(flag==true){
        System.out.println("-1");}

    }

}

import java.util.*;
public class distinct_digits {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int k=in.nextInt();
		Set<Integer> set = new HashSet<>();
		for(int i=n;i<=k;i++)
		{
			for(int j=0;j<String.valueOf(i).length();j++)
			{
				set.add(Character.getNumericValue(String.valueOf(i).charAt(j)));
			}
			if(set.size()==String.valueOf(i).length())
			{
				System.out.println(i);
				System.exit(0);
			}
			set.clear();
		}
		System.out.println("-1");
	}

}

import java.util.*;
import java.io.*;

public class problemA {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        // Scanner in = new Scanner(new File("input.in"));
        int l = in.nextInt();
        int r = in.nextInt();

        in.close();

        boolean found = false;

        int x = r + 1;

        for (int i = l; i < r + 1 && !found; i++) {
            String number = String.valueOf(i);
            int[] counter = new int[10];
            boolean noWork = false;
            for (int j = 0; j < number.length(); j++) {
                counter[Integer.parseInt(String.valueOf(number.charAt(j)))] = counter[Integer.parseInt(String.valueOf(number.charAt(j)))] + 1;
                if (counter[Integer.parseInt(String.valueOf(number.charAt(j)))] > 1) {
                    noWork = true;
                }
            }
            if (!noWork) {
                found = true;
                x = i;
            }
        }
        int minusOne = -1;
        // PrintWriter out = new PrintWriter(new File("output.out"));

        if (!found) {
            System.out.println(minusOne);
            // out.println(minusOne);
        } else {
            System.out.println(x);
            // out.println(x);
        }
        // out.close();
    }
}

import java.util.Arrays;
import java.util.Scanner;
public class distinctDigits
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int l=sc.nextInt();
        int r=sc.nextInt();
        int f=0;
        for (int i =l; i <=r ; i++)
        {
            int[] ar =new int[10];
             f=0;
             int t=i;
            while (t>0)
            {
                int rem=t%10;
                ar[rem]++;
                t=t/10;
                if(ar[rem]>1)
                {
                    f=1;
                    break;
                }
            }
            if(f==0)
            {
                System.out.println(i);
                break;
            }
        }
        if(f==1)
            System.out.println("-1");
    }
}

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt();
		boolean t=true;
		for(int i=a;i<=b;i++) {
			String s=i+"";
			int sum=0;
			int[] x=new int[s.length()];
			for(int j=0;j<s.length();j++)
				x[j]=s.charAt(j)-'0';
			Arrays.sort(x);
			for(int j=0;j<x.length-1;j++) {
				if(x[j]==x[j+1]) {
					sum++;
				}
			}
			if(sum==0) {
				System.out.print(i);
				t=false;
				break;
			}
		}
		if(t)
			System.out.print(-1);
	}
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Solve5 {

    public static void main(String[] args) throws IOException {
        PrintWriter pw = new PrintWriter(System.out);
        new Solve5().solve(pw);
        pw.flush();
        pw.close();
    }

    public void solve(PrintWriter pw) throws IOException {
        FastReader sc = new FastReader();
        int l = sc.nextInt(), r = sc.nextInt();
        for (int i = l; i <= r; i++) {
            int[] freq = freqencyOfDigits(getDigits(i));
            for (int j = 0; j < freq.length; j++) {
                if (freq[j] > 1) {
                    break;
                }
                if (j + 1 == freq.length) {
                    pw.println(i);
                    return;
                }
            }
        }
        pw.println(-1);
    }

    public int[] getDigits(long x) {
        char[] c = Long.toString(x).toCharArray();
        int[] digits = new int[c.length];
        for (int i = 0; i < c.length; i++) {
            digits[i] = c[i] - '0';
        }
        return digits;
    }

    public int[] freqencyOfDigits(int[] a) {
        int[] freq = new int[10];
        for (int i = 0; i < a.length; i++) {
            ++freq[a[i]];
        }
        return freq;
    }

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
            }
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (Exception e) {
            }
            return null;
        }

        public boolean hasNext() throws IOException {
            if (st != null && st.hasMoreTokens()) {
                return true;
            }
            String s = br.readLine();
            if (s == null || s.isEmpty()) {
                return false;
            }
            st = new StringTokenizer(s);
            return true;
        }
    }
}

import java.util.*;
import java.io.*;

public class EjerA5 {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int l,r, flag = 0;

    l = sc.nextInt();
    r = sc.nextInt();
    int temp = l-1;

    for (int i = l; i <= r; i++) {
        temp++;

        String tempstr = Integer.toString(temp);
        if (check(tempstr) == false) {
            System.out.println(tempstr);
            flag++;
            break;
        }

    }
        if (flag == 0) {
            System.out.println("-1");
        }

    }

    public static boolean check(CharSequence g) {
        for (int i = 0; i < g.length(); i++) {
            for (int j = i + 1; j < g.length(); j++) {
                if (g.charAt(i) == g.charAt(j)) {
                    return true;
                }
            }
        }
        return false;
    }
}

import java.util.*;
public class DistinctDigits{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        System.out.println(BruteForce(n,k));
    }
    public static String BruteForce(int n,int k){
        String array[]=new String[k-n+1];
        int j=0;
        for(int i=n;i<=k;i++){
            array[j]=Integer.toString(i);
            ++j;
        }
        for(int i=0;i<array.length;i++){
            int count[]=new int[10];
            boolean ok=true;
            for( j=0;j<array[i].length();j++){
                if(count[array[i].charAt(j)-'0']>0){
                    ok=false;
                    break;
                }else{
                    ++count[array[i].charAt(j)-'0'];
                }
            }
            if(ok){
                return array[i];
            }
        }
        return "-1";
    }
}

// practice with kaiboy
import java.io.*;
import java.util.*;

public class CF1228A extends PrintWriter {
	CF1228A() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1228A o = new CF1228A(); o.main(); o.flush();
	}

	boolean check(int x) {
		int used = 0;
		while (x > 0) {
			int d = x % 10;
			if ((used & 1 << d) != 0)
				return false;
			used |= 1 << d;
			x /= 10;
		}
		return true;
	}
	void main() {
		int l = sc.nextInt();
		int r = sc.nextInt();
		for (int x = l; x <= r; x++)
			if (check(x)) {
				println(x);
				return;
			}
		println(-1);
	}
}

import java.util.*;
import java.lang.*;

public class Solution{

    static void printUnique(int l, int r)
    {
        // Start traversing the numbers
        int c = 0;//to keep a count of non-distinct digits
        if(r < l)
            System.out.println("-1");
        for (int i=l ; i<=r ; i++)
        {
            int num = i;
            boolean visited[] = new boolean[10];

            // Find digits and maintain its hash
            while (num != 0)
            {
                // if a digit occcurs more than 1 time
                // then break
                if (visited[num % 10])
                    break;

                visited[num%10] = true;

                num = num/10;
            }

            // num will be 0 only when above loop
            // doesn't get break that means the
            // number is unique so print it.
            if (num == 0){
                System.out.print(i + " ");
                return;
            }
            else{
                c++;
            }
        }
        if(c > 0)
            System.out.println("-1");
    }
    public static void main(String args[])
    {
        Scanner ad = new Scanner(System.in);
        int l = ad.nextInt();
        int r = ad.nextInt();
        printUnique(l, r);
    }

}

import java.util.HashSet;
import java.util.Scanner;
public class Distinct_digit {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        for(int i=l;i<=r;i++)
        {
            char ch[] = (i+"").toCharArray();
            HashSet<Character> hs = new HashSet<>();
            for(char c:ch)
            {
                hs.add(c);
            }
            if(ch.length == hs.size()){
                System.out.println(i);
                return;
            }
        }
        System.out.println("-1");
    }
}

import java.io.*;
import java.util.*;

public class test {
	/*
	 * array list
	 *
	 * ArrayList<Integer> al=new ArrayList<>(); creating BigIntegers
	 *
	 * BigInteger a=new BigInteger(); BigInteger b=new BigInteger();
	 *
	 * hash map
	 *
	 * HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); for(int
	 * i=0;i<ar.length;i++) { Integer c=hm.get(ar[i]); if(hm.get(ar[i])==null) {
	 * hm.put(ar[i],1); } else { hm.put(ar[i],++c); } }
	 *
	 * while loop
	 *
	 * int t=sc.nextInt(); while(t>0) { t--; }
	 *
	 * array input
	 *
	 * int n = sc.nextInt(); int ar[] = new int[n]; for (int i = 0; i < ar.length;
	 * i++) { ar[i] = sc.nextInt(); }
	 */
	// private static final Scanner sc = new Scanner(System.in);
	// static Scanner sc = new Scanner(new BufferedReader(new
	// InputStreamReader(System.in)));

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	private static final Scanner sc = new Scanner(System.in);
	private static final FastReader fs = new FastReader();

	private static boolean getans(int i) {
		ArrayList<Integer> al = new ArrayList<Integer>();
		while (i > 0) {
			int r = i % 10;
			if (!al.contains(r)) {
				al.add(r);
			} else {
				return false;
			}
			i = i / 10;
		}
		return true;
	}

	public static void main(String[] args) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int i = a;
		boolean rs=false;
		for (; i <= b; i++) {
			if (getans(i)) {
				rs=true;
				break;
			}
		}
		if(rs)
			System.out.println(i);
		else
			System.out.println(-1);

	}

}/* till here */

//package com.company;
import java.util.Scanner;

public class Main {

    static boolean work(int x){
        String s=String.valueOf(x);
        for(int i=0;i<s.length();i++){
            for(int j=i+1;j<s.length();j++){
                if(s.charAt(i)==s.charAt(j)){
                    return  false;
                }
            }
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int l,r;
        l=input.nextInt();
        r=input.nextInt();
        int f=0;
        for(int i=l;i<=r;i++){
            if(work(i)){
                System.out.print(i);
                f=1;
                break;
            }
        }
        if(f==0) System.out.print(-1);
    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;
public class Main1{
	static long mod = 1000000007;
	static InputReader in = new InputReader(System.in);
	static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		//int t=in.readInt();
		//while(t-->0){
			int a=in.readInt();
			int b=in.readInt();
			int i=a,count=0;
			boolean ans=false;
			for(;i<=b;i++) {
				int p=i;
				Set<Integer> st=new HashSet<>();
				count=0;
				while(p!=0) {
					int r=p%10;
					count++;
					p=p/10;
					if(st.add(r)==false) {
						continue;
					}
				}
				if(st.size()==count) {
					ans=true;
					break;
				}
			}
			if(ans)
			System.out.println(i);
			else
				System.out.println(-1);
			//long n=in.readLong();
			// String a=in.readString();
		//}
	}

	static String removeChar(String s,int a,int b) {
		return s.substring(0,a)+s.substring(b,s.length());
	}
	static int[]  nextIntArray(int n){
		int[] arr= new int[n];
		int i=0;
		while(i<n){
			arr[i++]=in.readInt();
		}
		return arr;
	}
	static long[] nextLongArray(int n){
		long[]arr= new long[n];
		int i=0;
		while(i<n){
			arr[i++]=in.readLong();
		}
		return arr;
	}
	static int[]  nextIntArray1(int n) {
		int[] arr= new int[n+1];
		int i=1;
		while(i<=n){
			arr[i++]=in.readInt();
		}
		return arr;
	}
	static long[] nextLongArray1(int n){
		long[]arr= new long[n+1];
		int i=1;
		while(i<=n) {
			arr[i++]=in.readLong();
		}
		return arr;
	}
	static long gcd(long x, long y) {
		if (x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}
	static long pow(long n, long m) {
		if(m==0)
			return 1;
		else if(m==1)
			return n;
		else {
			long r=pow(n,m/2);
			if(m%2==0)
				return r*r;
			else
				return r*r*n;
		}
	}
	static long max(long a,long b,long c) {
		return Math.max(Math.max(a, b),c);
	}
	static long min(long a,long b,long c) {
		return Math.min(Math.min(a, b), c);
	}
	static class Pair implements Comparable<Pair> {
		int a, b;
		Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}
		public int compareTo(Pair o) {
			if (this.a != o.a)
				return Integer.compare(this.a, o.a);
			else
				return Integer.compare(this.b, o.b);
			// return 0;
		}
		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair) o;
				return p.a == a && p.b == b;
			}
			return false;
		}
		public int hashCode() {
			return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
		}
	}
	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		public String next() {
			return readString();
		}
		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}

import java.lang.* ;
import java.io.* ;
import java.util.* ;

// A U T H O R : s a n 1 d h y a

public class cf1228A {
	static long Mod1 = 1000000007;

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	/*
	 * public static void sortbyColumn(int arr[][], int col) { // Using built-in
	 * sort function Arrays.sort Arrays.sort(arr, new Comparator<int[]>() {
	 *
	 * @Override // Compare values according to columns public int compare(final
	 * int[] entry1, final int[] entry2) {
	 *
	 * // To sort in descending order revert // the '>' Operator if (entry1[col] >
	 * entry2[col]) return 1; else return -1; } }); // End of function call sort().
	 * }
	 */
/*	public static long binex(long x, long y) {
		x = x % Mod1;
		long ret = 1;
		while (y > 0) {
			if (y % 2 != 0) {
				ret = ret * x % Mod1;
			}
			x = x * x % Mod1;
			y >>= 1;
		}
		return ret;
	}
*/
/*	public static long mplr(long x, long y) {
		long ret = 0;
		while (y != 0) {
			if (y % 2 != 0) {
				ret = (ret + x) % Mod1;
			}
			x = (x + x) % Mod1;
			y >>= 1;
		}
		return ret;
	}
*/
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int l = sc.nextInt();
		int r=sc.nextInt();
		int flag=0;
		int i;
		for(i=l;i<=r;i++) {
			int a[]=new int[10];
			Arrays.fill(a,0);
			for(int j=i;j>0;j/=10) {
				int d=j%10;
				a[d]++;
			}
			int flag1=0;
			for(int j=0;j<10;j++) {
				if(a[j]>1)
				{
					flag1=1;
					break;
				}
			}
			if(flag1==0)
			{
				flag=1;
				break;
			}
		}
		if(flag==1)
		System.out.println(i);
		else
			System.out.println("-1");
	}
}

import java.io.*;
import java.util.*;
import java.lang.Math;
public class HelloWorld{

     public static void main(String []args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int end=sc.nextInt();
        int set=0;
        while(set==0 && n<=end)
        {
            if(isdif(n)==1)
            set=1;
            else
            n++;
        }
        if(set==1)
        System.out.print(n);
        else
         System.out.print("-1");
     }
     static int isdif(int n)
     {
         HashSet<Integer> h=new HashSet();
         while(n>=1)
         {
             if(h.contains(n%10))
             return 0;
             h.add(n%10);
             n=n/10;
         }
         return 1;
     }
}

/**
 * @author egaeus
 * @mail sebegaeusprogram@gmail.com
 * @veredict Accepted
 * @url <https://codeforces.com/problemset/problem/1228/A>
 * @category adhoc
 * @date 30/09/2019
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CF1228A {
    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        for (String ln; (ln = in.readLine()) != null; ) {
            StringTokenizer st = new StringTokenizer(ln);
            int a = parseInt(st.nextToken()), b = parseInt(st.nextToken());
            boolean ws = false;
            for (int i = a; i <= b; i++)
                if (check(i)) {
                    System.out.println(i);
                    ws = true;
                    break;
                }
            if (!ws) System.out.println(-1);
        }
    }

    private static boolean check(int a) {
        boolean[] v = new boolean[10];
        for (; a > 0; a /= 10)
            if (v[a % 10]) return false;
            else v[a % 10] = true;
        return true;
    }
}

import java.util.Scanner;

public class DistinctDigits {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        boolean val = false;
        for (int x = l; x <= r; x++)
        {
            String s = Integer.toString(x);
            boolean work = true;
            for (int i = 0; i < s.length(); i++)
            {
                if (s.indexOf(s.substring(i,i+1))!=s.lastIndexOf(s.substring(i,i+1)))
                {
                    work = false;
                    break;
                }
            }
            if (work)
            {
                val = true;
                System.out.println(x);
                break;
            }
        }
        if (!val)
            System.out.println(-1);
    }
}

import java.util.Scanner;

public class A {

    public static boolean distinct(int x) {
        int[] count = new int[10];
        while (x > 0) {
            int toRegister = x % 10;
            count[toRegister]++;
            x /= 10;
        }
        boolean distinct = true;
        for (int e : count) {
            if (e > 1) {
                distinct = false;
                break;
            }
        }
        return distinct;
    }

    public static void main(String args[]) {
        Scanner lec = new Scanner(System.in);
        int l = lec.nextInt(), r = lec.nextInt(), ans = -1;
        for (int i = l; i <= r; ++i) {
            if (distinct(i) && ans == -1) {
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }
}

import java.util.Scanner;
public class Main {
	public static int isDistinct(int i) {
		int y=i;
		int n=i;
		while(i>0) {
			int u=i%10;
			n=i/10;
			i/=10;
			while(n>0) {
				if(u == n%10)
					return -1;
				else
					n/=10;
			}
		}
	return y;
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int flag=0;
		for(int i=a;i<=b;i++)
		if(isDistinct(i)!=-1) {
			System.out.println(i);
			flag=1;
			break;
		}
		if(flag==0)
			System.out.println(-1);
		}
	}

import java.util.Scanner;

public class A {

    public static boolean distinct(int x) {
        int[] count = new int[10];
        while (x > 0) {
            int toRegister = x % 10;
            count[toRegister]++;
            x /= 10;
        }
        for (int e : count) {
            if (e > 1) {
                return false;
            }
        }
        return true;
    }

    public static void main(String args[]) {
        Scanner lec = new Scanner(System.in);
        int l = lec.nextInt(), r = lec.nextInt(), ans = -1;
        for (int i = l; i <= r; ++i) {
            if (distinct(i) && ans == -1) {
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }
}

import java.util.*;
import java.lang.*;
import java.io.*;
public class discount
{
 public static void function(long q,long u)
{
	int j,flag=0,k,l,count=0;
         int i,x;

		int array[]=new int[6];

		for(i=(int)q;i<=(int)u;i++)
		{
			x=i;count=0;flag=0;
			for(j=0;(x!=0);j++)
			{
				array[j]=(x%10);
				x=x/10;
				count++;
			}
			for(k=0;k<count-1;k++)
			{
				for(l=k+1;l<count;l++)
				{
					if(array[k]==array[l]){flag=1;break;}
				}
				if(flag==1){break;}

			}
			if(flag==0){System.out.println(i);break;}

	}

	if(flag!=0){System.out.println("-1");}

}
	public static void main(String args[])
	{
		Scanner sc =new Scanner(System.in);
long a=1,b=1;

    if(sc.hasNextLong()){a=sc.nextLong();}else{return; }

       if(sc.hasNextLong()){   b=sc.nextLong();}else{return;}

sc.close();

		function(a,b);
		}
	}

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
	    try (Scanner sc = new Scanner(System.in)){
            int l = sc.nextInt();
            int r = sc.nextInt();
            for (int i = l; i <= r; i++){
                if (checkDifferentDigits(i)){
                    System.out.println(i);
                    return;
                }
            }
            System.out.println(-1);
        } catch (Exception e){
	        throw new IllegalStateException(e);
        }
    }

    public static boolean checkDifferentDigits(int number){
        String digits = String.valueOf(number);
        Set<Character> characterSet = new HashSet<>();
        for (int i = 0; i < digits.length(); i++){
            if (characterSet.contains(digits.charAt(i)))
                return false;
            else
                characterSet.add(digits.charAt(i));
        }
        return true;
    }
}

import java.util.Scanner;

public class A {

    public static boolean distinct(int x) {
        int[] count = new int[10];
        while (x > 0) {
            int toRegister = x % 10;
            count[toRegister]++;
            x /= 10;
        }
        boolean distinct = true;
        for (int e : count) {
            if (e > 1) {
                distinct = false;
            }
        }
        return distinct;
    }

    public static void main(String args[]) {
        Scanner lec = new Scanner(System.in);
        int l = lec.nextInt(), r = lec.nextInt(), ans = -1;
        for (int i = l; i <= r; ++i) {
            if (distinct(i) && ans == -1) {
                ans = i;
            }
        }
        System.out.println(ans);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ky112233
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int l = in.nextInt();
            int r = in.nextInt();
            for (int i = l; i <= r; i++) {
                int[] temp = new int[10];
                int temp2 = i;
                while (temp2 > 0) {
                    temp[temp2 % 10]++;
                    temp2 /= 10;
                }
                boolean flag = true;
                for (int num : temp) {
                    if (num > 1) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    out.println(i);
                    return;
                }
            }

            out.println(-1);
        }

    }
}

import java.util.HashMap;
import java.util.Scanner;
public class Solution
{
	public static boolean same(int n) {
		char[] n1 = String.valueOf(n).toCharArray();
		HashMap<Character, Integer> map = new HashMap<Character, Integer>();
		for(int i = 0;i<n1.length;i++) {
			if(map.containsKey(n1[i])) {
				return false;
			}
			else {
				map.put(n1[i], 1);
			}
		}
		return true;
	}
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int l = sc.nextInt();
    	int r = sc.nextInt();
    	boolean flag = false;
    	while(l <= r) {
    		if(same(l)) {
    			System.out.println(l);
    			flag = true;
    			break;
    		}
    		else {
    			l+=1;
    		}
    	}
    	if(!flag) {
    		System.out.println(-1);
    	}
    }
}

import java.util.HashSet;
import java.util.*;

public class Test {
    private static boolean isDist(long n){
        String s = n+""; int len=s.length();
        HashSet<Character> hs = new HashSet<>();
       // System.out.println(s);
        for(int i=0;i<len;i++){
            char ch = (char)s.charAt(i);
         //   System.out.println(ch);
            hs.add(ch);
        }
       // System.out.println(hs.size());
        if(hs.size()==len)
            return true;
        return  false;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l  = sc.nextInt();
        int r = sc.nextInt();
        long n =l;
        boolean flag = false;
        while(true){
            if(isDist(n)){
                flag = true;
                break;
            }else{
                n++;
            }
            if(n>r){
                break;
            }
        }
        if(flag)
            System.out.println(n);
        else
            System.out.println("-1");

    }

}

import java.util.*;
public class Main {
    public static void main(String[] args) {
        int l,r;
		Scanner in=new Scanner(System.in);
		l=in.nextInt();
		r=in.nextInt();
		int ans=-1;
		String x;
		for(int i=l;i<=r;i++){
			x=Integer.toString(i);
			if(x.length()==x.chars().distinct().count())
			{
				ans=i;
				break;
			}
		}
	    System.out.println(ans);
    }
}

import java.util.*;

import java.io.*;

import java.math.*;
public class Solution implements Runnable{
    FastScanner sc;
    PrintWriter pw;
    final class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public long nlo() {
            return Long.parseLong(next());
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public String nli() {
            String line = "";
            if (st.hasMoreTokens()) line = st.nextToken();
            else try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            while (st.hasMoreTokens()) line += " " + st.nextToken();
            return line;
        }

        public double nd() {
            return Double.parseDouble(next());
        }
    }
    public static void main(String[] args) throws Exception
    {
        new Thread(null,new Solution(),"codeforces",1<<28).start();
    }
    public void run()
    {
        sc=new FastScanner();
        pw=new PrintWriter(System.out);
        try{solve();}
        catch(Exception e)
        {System.out.println(e);}
        pw.flush();
        pw.close();
    }
    public long gcd(long a,long b)
    {
        return b==0L?a:gcd(b,a%b);
    }
    public long ppow(long a,long b,long mod)
    {
        if(b==0L)
        return 1L;
        long tmp=1;
        while(b>1L)
        {
            if((b&1L)==1)
            tmp*=a;
            a*=a;
            a%=mod;
            tmp%=mod;
            b>>=1;
        }
        return (tmp*a)%mod;
    }
    public  int gcd(int x,int y)
    {
        return y==0?x:gcd(y,x%y);
    }
    //////////////////////////////////
    /////////////  LOGIC  ///////////
    ////////////////////////////////

    public void solve() throws Exception
    {
       int l=sc.ni();
       int r=sc.ni();
       for(int i=l;i<=r;i++)
       {
           int x=i,res=0;
           int[] arr=new int[10];
           while(x>0)
           {if(arr[x%10]>0)
            res=-1;
                else
            arr[x%10]++;
            x/=10;
           }
           if(res==0)
           {
               pw.println(i);
               return;
           }
       }
       pw.println(-1);
    }
}

/*==============================================
Name        : Shadman Shariar                 ||
Email       : shadman.shariar@northsouth.edu  ||
University  : North South University (NSU)    ||
Facebook    : shadman.shahriar.007            ||
==============================================*/

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner (System.in);

		int l = input.nextInt();
		int r = input.nextInt();
		int k = -1;
		String t2 = "";
		for (int i = l; i <= r; i++) {

			String s = Integer.toString(i);
			int c = 0;
			for (int j = 0; j < s.length()-1; j++) {
				for (int j2 = j+1; j2 < s.length(); j2++) {
					if (s.charAt(j)==s.charAt(j2)) {
						c++;
						break;
					}
				}
			}

			if (c==0) {
				k++;
				t2=s;
				break;
			}

		}
		if (k==0){
			System.out.println(t2);
		}
		else {
			System.out.println(k);
		}

		input.close();
	}
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class comp
{
    private static boolean help(int n){
        String s=String.valueOf(n);
        Set<Character> ss=new HashSet<>();
        for(char c:s.toCharArray()){
            ss.add(c);
        }
        return ss.size()==s.length();
    }
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int i=0;
		for(i=a;i<=b;i++){
		    if(help(i)){
		        System.out.println(i);
		        break;
		    }
		}
		if(i==b+1){
		    System.out.println(-1);
		}

	}
}

//Distinct digits
import java.util.Scanner;
public class E1 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String cadena = sc.nextLine();
		int aux = 0;
		String [] temporal = new String[2];
		for (int i = 0; i < 2; i++) {
			temporal[i] = "";
		}
		for (int i = 0; i < cadena.length(); i++) {
			if(Character.isDigit(cadena.charAt(i)) || (cadena.charAt(i)) == '-')
				temporal[aux] = temporal[aux] + cadena.charAt(i);
			else
				aux++;
		}
		int r = Integer.parseInt(temporal[1]);
		int i = Integer.parseInt(temporal[0]);
		String tmp;
		int flag = 0;
		int flag_2 = 0;
		int cont_2 = 0;
		int cont = 0;
		while (i <= r && flag_2 == 0) {
			tmp = Integer.toString(i);
			while (cont < (Integer.toString(i).length()) - 1) {
				cont_2 = cont + 1;
				while (cont_2 < (Integer.toString(i).length())){
					if (tmp.charAt(cont) == tmp.charAt(cont_2))
						flag++;
					cont_2++;
				}
				cont++;
			}
			if (flag == 0)
				flag_2++;
			else {
				flag = 0;
				cont_2 = 0;
				cont = 0;
				i++;
			}
		}
		if (flag_2 == 0)
			System.out.println(-1);
		else
			System.out.println(i);
	}
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
     public static void main (String[] args) throws java.lang.Exception
     {
     	Scanner in =new Scanner(System.in);
		int t=1,n,i,j,m=0,k,p=0,x,o,y;
		String s;
		for(i=0;i<t;i++)
		{
		    s="";x=0;
		    n=in.nextInt();
		    m=in.nextInt();
		    for(j=n;j<=m;j++)
		    {
		         for(k=0;k<10;k++)
		         {
		              y=j;x=0;
		              while(y>0)
		              {
		                   p=y%10;
		                   if(p==k)
		                        x++;
		                   y=y/10;
		              }
		              if(x>1)
		              break;
		         }
		         if(k==10)
		         {     System.out.println(j);break;}
		    }
		    if(j==m+1)
		    System.out.println("-1");
		}
	}
}

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {

    // Complete the maximumSum function below.
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    // private static final FastReader scanner = new FastReader();

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader scanner = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int a=scanner.nextInt();
        boolean t=false;
        int b=scanner.nextInt();
        for(int i=a;i<=b;i++){
            int l=String.valueOf(i).length();
            int c=i;
            Set<Integer> x=new HashSet<>();
            while(c>0){
                x.add(c%10);
                c/=10;
            }
            if(x.size()==l){
                w.println(i);
                t=true;
                break;
            }
        }
        if(!t)
          w.println(-1);
        w.close();
    }
}

  import java.io.*;
import java.util.*;
import java.lang.*;

    public class d {
    	public static void main (String[] args) {
    	PrintWriter pw=new PrintWriter(System.out);
    	Scanner sc=new Scanner(System.in);
        int r=sc.nextInt();
       int l=sc.nextInt();
        int[] a=new int[10];
    int i=0,f1=0;
    for(i=r;i<=l;i++)
       {      int v=i,f=0;
              a=new int[10];
              while(v>0){
                   a[v%10]++;
                     v=v/10;
                   }
             for(int j=0;j<10;j++){
                if(a[j]>1){
                  f=1;
                  a=null;
                  break;
                 }
              }
       if(f==0){
        f1=1;
        break;}
}

      if(f1==1)
       pw.println(i);
     else
     pw.println(-1);
pw.close();

    	}
    }

import java.util.HashSet;
import java.util.Scanner;

public class DistinctDigits {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int l=scan.nextInt();
		int r=scan.nextInt();
		int len=0;
		HashSet hs=new HashSet();
		for(int i=l;i<=r;i++) {
			int c=i;
			len=String.valueOf(c).length();
			while(c!=0) {
				int a=c%10;
				hs.add(a);
				c=c/10;
			}
			if(hs.size()==len) {
				String s=String.valueOf(i);
				System.out.println(s);
				break;
			}
			else hs.clear();
		}
		if(hs.size()!=len) System.out.println(-1);
	}

}

import java.util.Scanner;
public class MyClass {
    public static void main(String args[]) {
      Scanner x=new Scanner(System.in);
      int a,b,c=0,d,e,f,hhh=0,num,z;
      a=x.nextInt();
      b=x.nextInt();
      if(a!=b)
      {for(num=a;num<=b;num++)
      {hhh=0;c=num;

          int[] arr=new int[10];
          while(c!=0){
              d=c%10;
              c=c/10;
           arr[d]++;
           if(arr[d]>1){hhh=1;break;}
          }
          if(hhh==0&&c==0)
          break;

      }if(hhh==0&&c==0)
          System.out.println(num);
          else
          System.out.println(-1);
      }
      else
      {num=a;
          int[] arr=new int[10];
          while(a!=0){
              d=a%10;
              a=a/10;
           arr[d]++;
           if(arr[d]>1){hhh=1;break;}
          }
          if(hhh==0&&c==0)
          System.out.println(num);
          else
          System.out.println(-1);

      }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        PrintWriter pw = new PrintWriter(System.out);
        Input(new FastReader(), pw);
        pw.flush();
        pw.close();
    }

    public static void Input(FastReader input, PrintWriter pw) {
        int m, n = 0;
        n = input.nextInt();
        m = input.nextInt();
        int i = n;
        while (i <= m) {
            String b = String.valueOf(i);
            Map<Character, Integer> map = new HashMap<>();

            IntStream.range(0, b.length()).forEach(j -> {
                if (!map.containsKey(b.charAt(j))) {
                    map.put(b.charAt(j), 1);
                } else {
                    int o = map.get(b.charAt(j)) + 1;
                    map.put(b.charAt(j), o);
                }
            });
            boolean v = map.entrySet().stream().noneMatch(l -> l.getValue() > 1);
            if (v) {
                pw.println(b);
                pw.flush();
                pw.close();
                System.exit(0);
            }
            i++;
        }
        pw.println(-1);

    }

    public static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String string = "";
            try {
                string = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return string;
        }

        char nextChar() {
            return next().charAt(0);
        }

        String[] nextStringArray() {
            String[] str = null;
            try {
                str = this.br.readLine().trim().split(" ");
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextIntArray() {
            String[] data = nextStringArray();
            int[] a = new int[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Integer.parseInt(data[i]);
            }

            return a;
        }

        Integer[] nextIntegerArray() {
            String[] data = nextStringArray();
            Integer[] a = new Integer[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Integer.parseInt(data[i]);
            }

            return a;
        }

        long[] nextLongArray() {
            String[] data = nextStringArray();
            long[] a = new long[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Long.parseLong(data[i]);
            }

            return a;
        }

        public boolean hasNext() throws IOException {
            if (st != null && st.hasMoreTokens()) {
                return true;
            }
            String s = br.readLine();
            if (s == null || s.isEmpty()) {
                return false;
            }
            st = new StringTokenizer(s);
            return true;
        }

    }

}

import java.util.Arrays;
import java.util.Scanner;

public class CodeForces2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong(); long r = sc.nextLong(); String s;
        label1: for (long i = l; i <= r; i++) {
            s = i+"";
            if(s.length() == 1){
                System.out.println(l);
                return;
            }
            else{
            char arr[] = s.toCharArray();
            Arrays.sort(arr);
               for (int j = 0; j < arr.length-1; j++) {
                if(arr[j] == arr[j+1]) break;
                   else if (arr[j] != arr[j + 1] && j == arr.length - 2) {
                       System.out.println(i);
                       return;
                   }
                }
            }
        }
        System.out.println("-1");
    }
}

//package com.company;
import com.sun.nio.sctp.SctpStandardSocketOptions;

import javax.swing.*;
import java.util.Calendar;
import java.net.StandardSocketOptions;
import java.util.*;
import java.util.Calendar;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Random;
import java.util.StringTokenizer;
import java.io.*;
import java.util.ArrayList;
/*
						            	    DOMINGO_GIRL :)
											─────────▄──────────────▄
											────────▌▒█───────────▄▀▒▌
											────────▌▒▒▀▄───────▄▀▒▒▒▐
											───────▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐
											─────▄▄▀▒▒▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐
											───▄▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀██▀▒▌
											──▐▒▒▒▄▄▄▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄▒▒▌
											──▌▒▒▐▄█▀▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐
											─▐▒▒▒▒▒▒▒▒▒▒▒▌██▀▒▒▒▒▒▒▒▒▀▄▌
											─▌▒▀▄██▄▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌
											─▌▀▐▄█▄█▌▄▒▀▒▒▒▒▒▒░░░░░░▒▒▒▐ Wow
											▐▒▀▐▀▐▀▒▒▄▄▒▄▒▒▒▒▒░░░░░░▒▒▒▒▌
										   	▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒░░░░░░▒▒▒▐
											─▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌
											─▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
											──▀▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▒▒▒▒▌
											────▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀
											───▐▀▒▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀
											──▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▀
                                    	*/

public class Main {
    public static void main(String[] arg) {
        Scanner sc = new Scanner(System.in);int max=0;
        int n=sc.nextInt();int m=sc.nextInt();boolean f=false;
        //String s1=Integer.toString(n);String s2=Integer.toString(m);
        for(int i=n;i<=m;i++){

            if(check(i)){
                System.out.println(i);f=true;break;
            }
        }
        if(!f)System.out.println(-1);

    }
    public static boolean check(int x){
        Set<Integer> set = new HashSet<Integer>();
        //String s=Integer.toString(x);
        int c=0;
        for( ;x>0;x=x/10){
            set.add(x%10);c++;
        }
        return (set.size()==c);
    }

    /*This function divides a by greatest
        divisible power of b*/
    static int maxDivide(int a, int b)
    {
        while(a % b == 0)
            a = a/b;
        return a;
    }

    /* Function to check if a number
    is ugly or not */
    static int isUgly(int no)
    {
        no = maxDivide(no, 2);
        no = maxDivide(no, 3);
        no = maxDivide(no, 5);

        return (no == 1)? 1 : 0;
    }

    /* Function to get the nth ugly
    number*/
    static int getNthUglyNo(int n)
    {
        int i = 1;

        // ugly number count
        int count = 1;

        // check for all integers
        // until count becomes n
        while(n > count)
        {
            i++;
            if(isUgly(i) == 1)
                count++;
        }
        return i;
    }

    static int findLongestConseqSubseq(int arr[], int n)
    {
    /* We insert all the array elements into
    unordered set. */
        HashSet<Integer> S = new HashSet<Integer>();
        for (int i = 0; i < n; i++)
            S.add(arr[i]);

        // check each possible sequence from the start
        // then update optimal length
        int ans = 0;
        for (int i = 0; i < n; i++)
        {

            // if current element is the starting
            // element of a sequence
            if(S.contains(arr[i]))
            {

                // Then check for next elements in the
                // sequence
                int j = arr[i];

                // increment the value of array element
                // and repeat search in the set
                while (S.contains(j))
                    j++;

                // Update optimal length if this length
                // is more. To get the length as it is
                // incremented one by one
                ans = Math.max(ans, j - arr[i]);
            }
        }
        return ans;
    }

    static int nextPowerOf2(int n)
    {
        int count = 0;

        // First n in the below
        // condition is for the
        // case where n is 0
        if (n > 0 && (n & (n - 1)) == 0)
            return n;

        while(n != 0)
        {
            n >>= 1;
            count += 1;
        }

        return 1 << count;
    }

    public static int ArrivalOfTheGeneral(int n,int a[]){
        int max=Integer.MIN_VALUE;int maxIndex=0;
        for(int i=0;i<a.length;i++){
            if(a[i]>max){
                max=a[i];maxIndex=i;
            }
        }
        //System.out.println(max+" "+maxIndex);
        int c1=0;
        for(int i=maxIndex;i>0;i--){
            int temp=a[maxIndex];
            a[maxIndex]=a[i-1];
            a[i-1]=temp;
            c1++;maxIndex--;
        }
        //System.out.println(Arrays.toString(a));
        int min=Integer.MAX_VALUE;int minIndex=0;
        for(int i=0;i<a.length;i++){
            if(a[i]<=min){
                min=a[i];minIndex=i;
            }
        }
        int c2=0;
        for(int i=minIndex;i<a.length-1;i++){
            int temp=a[minIndex];
            a[minIndex]=a[i+1];
            a[i+1]=temp;
            c2++;minIndex++;
        }
        return c1+c2;
    }
    public static String IWannaBetheGuy(int n,int x,int ax[],int y,int ay[]){

        ArrayList<Integer>ar=new ArrayList<>();
        for(int i=1;i<=n;i++)ar.add(i);
        for(int i=0;i<ax.length;i++){
            if(ar.contains(ax[i]))ar.remove(ar.indexOf(ax[i]));
        }
        for(int i=0;i<ay.length;i++){
            if(ar.contains(ay[i]))ar.remove(ar.indexOf(ay[i]));
        }
        if(ar.size()==0)return "I become the guy.";
        else  return "Oh, my keyboard!";

    }

    public static String UltraFastMathematician(String s1,String s2){

        String res="";
        for(int i=0;i<s1.length();i++){
            if((s1.charAt(i)=='1'&&s2.charAt(i)=='1')||(
                    s1.charAt(i)=='0'&&s2.charAt(i)=='0'))
                res+='0';
            else res+='1';
        }
        return res;
    }

    public static int InsomniaCure(int k,int l,int m,int n,int d){
        int dameged=0;
        for(int i=1;i<=d;i++){
            if(i%k==0||i%l==0||i%n==0||i%m==0)dameged++;
        }
        return dameged;
    }

    // function to find the maximum
    // number of segments
    static int maximumSegments(int n, int a,
                               int b, int c)
    {
        // stores the maximum number of
        // segments each index can have
        int dp[] = new int[n + 10];

        // initialize with -1
        Arrays.fill(dp, -1);

        // 0th index will have 0 segments
        // base case
        dp[0] = 0;

        // traverse for all possible
        // segments till n
        for (int i = 0; i < n; i++)
        {
            if (dp[i] != -1)
            {

                // conditions
                if(i + a <= n )    //avoid buffer overflow
                    dp[i + a] = Math.max(dp[i] + 1,
                            dp[i + a]);

                if(i + b <= n )    //avoid buffer overflow
                    dp[i + b] = Math.max(dp[i] + 1,
                            dp[i + b]);

                if(i + c <= n )    //avoid buffer overflow
                    dp[i + c] = Math.max(dp[i] + 1,
                            dp[i + c]);
            }
        }
        return dp[n];
    }

    // Recursive function to return gcd of a and b
    static int gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    // method to return LCM of two numbers
    static int lcm(int a, int b)
    {
        return (a*b)/gcd(a, b);
    }

    // Function to return LCM of two numbers without GCD method
    public static int findLCM(int a, int b)
    {
        int lar = Math.max(a, b);
        int small = Math.min(a, b);
        for (int i = lar; ; i += lar) {
            if (i % small == 0)
                return i;
        }
    }

    //Function to find gcd of array of numbers
    static int findGCD(int arr[], int n)
    {
        int result = arr[0];
        for (int i = 1; i < n; i++)
            result = gcd(arr[i], result);

        return result;
    }

    // method to print the divisors
    static void printDivisors(int n)
    {
        TreeSet<Integer>t=new TreeSet<>();
        // Note that this loop runs till square root
        for (int i=1; i<=Math.sqrt(n); i++)
        {
            if (n%i==0)
            {
                // If divisors are equal, print only one
                if (n/i == i)
                    t.add(i);

                else // Otherwise print both
                    t.add(i);t.add(n/i);
            }
        }
        //Collections.sort(h);
        Iterator<Integer> ir = t.iterator();
        while(ir.hasNext())System.out.println(ir.next());
    }

    // A function to print all prime factors
    // of a given number n
    public static void primeFactors(int n)
    {
        // Print the number of 2s that divide n
        while (n%2==0)
        {
            System.out.print(2 + " ");
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2) because
        //difference of two prime factors must be at least 2
        //Every composite number has at least one prime factor less than or equal to square root of itself.
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                System.out.print(i + " ");
                n /= i;
            }
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2)
            System.out.print(n);
    }

    static int findIndex(int[] a, int item)
    {
        for(int i = 0; i < a.length; ++i)
            if(item == a[i])
                return i;
        return -1;
    }
    static boolean isPal(char[] s) {
        for (int i = 0; i < s.length / 2; i++)
            if (s[i] != s[s.length - i - 1])
                return false;
        return true;
    }
    static String get(int sec) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, sec);
        return new SimpleDateFormat("HH:mm:ss").format(calendar.getTime());

    }
    static class Pair  {
        int idx;
        int first, second;

        Pair(int a, int b, int c) {
            first = a;
            second = b;
            idx = c;
        }

    }

    //System.out.println(s);
    //pw.println(s);

/*
    static void moveT(int []a,int idx){
        int t=a[idx];
        for(int i=idx;i>0;i--){
            a[i]=a[i-1];
        }
        a[0]=t;
    }
    static int findIndex(int[] a, int item)
    {
        for(int i = 0; i < a.length; ++i)
            if(item == a[i])
                return i;
        return -1;
    }
    static class pair implements Comparable<pair>{
        int idx;
        int value;

        pair(int idx,int value){
            this.idx=idx;
            this.value=value;
        }

        @Override
        public int compareTo(pair o) {
            return o.value-this.value;
        }
    }

*/

    //Equilibrium index of an array is an index such that the sum of elements
    // at lower indexes is equal to the sum of elements at higher indexes.

    int equilibrium(int arr[], int n)
    {
        int sum = 0; // initialize sum of whole array
        int leftsum = 0; // initialize leftsum

        /* Find sum of the whole array */
        for (int i = 0; i < n; ++i)
            sum += arr[i];

        for (int i = 0; i < n; ++i) {
            sum -= arr[i]; // sum is now right sum for index i

            if (leftsum == sum)
                return i;

            leftsum += arr[i];
        }

        /* If no equilibrium index found, then return 0 */
        return -1;
    }

}

import java.util.*;

public class Digits {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        final int L = sc.nextInt();
        final int R = sc.nextInt();

        int place1T, place2T, place3T, place4T, place5T, place6T;
        int confirm, last, confirm2 = 0, test2;
        for (int test = L; test <= R; test++) {
            confirm = 0;
            test2 = test;
            place1T = test2/100000;
            test2 %= 100000;
            place2T = test2/10000;
            test2 %= 10000;
            place3T = test2/1000;
            test2 %= 1000;
            place4T = test2/100;
            test2 %= 100;
            place5T = test2/10;
            place6T = test2%10;
            if (place1T == 0){
                place1T = 11;
                if (place2T == 0){
                    place2T = 12;
                    if (place3T == 0){
                        place3T = 13;
                        if (place4T == 0){
                            place4T = 14;
                            if (place5T == 0){
                                place5T = 15;
                                if (place6T == 0){
                                    place6T = 16;
                                }
                            }
                        }
                    }
                }
            }
            if (place1T == place2T) {
                confirm = 1;
            }
            if (place1T == place3T) {
                confirm = 1;
            }
            if (place1T == place4T) {
                confirm = 1;
            }
            if (place1T == place5T) {
                confirm = 1;
            }
            if (place1T == place6T) {
                confirm = 1;
            }
            if (place2T == place3T) {
                confirm = 1;
            }
            if (place2T == place4T) {
                confirm = 1;
            }
            if (place2T == place5T) {
                confirm = 1;
            }
            if (place2T == place6T) {
                confirm = 1;
            }
            if (place3T == place4T) {
                confirm = 1;
            }
            if (place3T == place5T) {
                confirm = 1;
            }
            if (place3T == place6T) {
                confirm = 1;
            }
            if (place4T == place5T) {
                confirm = 1;
            }
            if (place4T == place6T) {
                confirm = 1;
            }
            if (place5T == place6T) {
                confirm = 1;
            }
            if (confirm == 0){
                System.out.println(test);
                confirm2 = 1;
                break;
            }
        }
        if (confirm2 == 0){
            System.out.println(-1);
        }
    }
}

import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;

public class Main implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;
			do
			{
				if(c<'0'||c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}

		public double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Main(),"Main",1<<27).start();
	}

	public void run(){
        InputReader sc=new InputReader(System.in);
        PrintWriter out=new PrintWriter(System.out);
            int l=sc.nextInt();
            int r=sc.nextInt();
            int flag=0,flag1=0;
            while(l!=r+1)
            {
                HashSet<Integer>set=new HashSet<>();
                int y=l;
                while(y!=0)
                {
                    if(set.contains(y%10))
                    {
                        flag=1;
                        break;
                    }
                    set.add(y%10);
                    y=y/10;
                }
                if(flag==0)
                {
                    out.println(l);
                    flag1=1;
                    break;
                }
                l++;
                flag=0;
            }
            if(flag1!=1)
            out.println("-1");
        out.flush();
		out.close();
	}
}

import java.io.*;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class test
{
    public static void main(String[] args)
    {

        Scanner sc = new Scanner(System.in);

       // System.out.println("Eneter ");

        int start= sc.nextInt();
        int end= sc.nextInt();

        for(int i=start; i<= end ; i++)
        {
            Set<Integer> s= new HashSet<>();
            int n=i;
            int cnt=0;
            while(n>0)
            {
                cnt++;
                int c = n%10;
                if(s.add(c)==false)
                    break;
                s.add(c);
                n=n/10;

            }
            if(s.size()==cnt){
                System.out.println(i);
                return;
            }}

        System.out.println(-1);
    }
}

import java.util.*;
import java.io.*;

public class Main {
	public static boolean work(int n) {
		int a[] = new int[10];
		while(n > 0) {
			if(++a[n%10] > 1) return false;
			n /= 10;
		}
		return true;
	}
	public static void solve(InputReader in) {
		int x = in.readInt();
		int y = in.readInt();
		for(int i = x; i<=y; i++) {
		    if(work(i)) {
		    	System.out.println(i);
		    	return;
		    }
		}
		System.out.println(-1);
	}

    public static void main(String[] args) {
    	InputReader in = new InputReader(System.in);
    	int t = 1;
    	while(t-- > 0) {
    		solve(in);
    	}
    }
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

     public String next() {
		return readString();
	}

     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class Diff {
	public static void main(String[] args) {
		int n, m;

		Scanner s = new Scanner(System.in);
		n= s.nextInt();
		m=s.nextInt();
		int i;
		for (i = n; i <= m; i++) {
			if(check(i)){
				System.out.println(i);
				break;
			}
		}
		if(i==(m+1))
		System.out.println(-1);

	}
	public static boolean check(int i){
		String a=new Integer(i).toString();
		for (int j = 0; j < a.length()-1; j++) {
			char charAt[] = new char[1];
			charAt[0]=a.charAt(j);
			String t=a.substring(j+1);
//			System.out.println(t);
			if (t.contains(new String(charAt))) {
				return false;
			}
		}

		return true;
	}

}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Optional;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {

    static final long MOD = (long) (1e9 + 7);
    private static PrintWriter out;

    public static void main(String[] args) throws FileNotFoundException {

        // Input from file
        // File inputFile = new File("JavaFile.txt");
        // File outputFile = new File("JavaOutputFile.txt");
        // FileReader fileReader = new FileReader(inputFile);
        // Here it ends

        MyScanner sc = new MyScanner();
        // MyScanner sc = new MyScanner(fileReader);

        out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console
        // out = new PrintWriter(new PrintStream(outputFile)); // Output to file

        getAns(sc);

        out.close();
    }

    /*
     *Don't use builtin function (Math.ceil)
     */

    private static void mprintln(Object... ar) {
        for (Object i : ar) {
            out.print(i + " ");
        }
        out.println();
    }

    private static void mprint(Object... ar) {
        for (Object i : ar) {
            out.print(i + " ");
        }
    }

    private static void getAns(MyScanner sc) {
        int l = sc.ni(), r = sc.ni();
        while (l <= r) {
            if (allIsWell(l)) {
                out.println(l);
                return;
            }
            ++l;
        }
        out.println(-1);
    }

    private static boolean allIsWell(int n) {
        HashSet<Integer> set = new HashSet<>();
        while (n > 0) {
            int cur = n % 10;
            if (set.contains(cur)) return false;
            set.add(cur);
            n /= 10;
        }

        return true;
    }

    static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }

        char nc() {
            return nn().charAt(0);
        }

        int ni() {
            return Integer.parseInt(nn());
        }

        long nl() {
            return Long.parseLong(nn());
        }

        double nd() {
            return Double.parseDouble(nn());
        }

        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = ni();
            }
            return ar;
        }

        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = ni();
            }
            return ar;
        }

        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nl();
            }
            return ar;
        }

        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nl();
            }
            return ar;
        }
    }
}

import java.util.Scanner;

public class DistinctDigits {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int l = scan.nextInt();
		int r = scan.nextInt();
		String x = "";
		int tally = 0;
		String temp = "";
		for(int i = 0; i <= r - l + 1; i++) {
			x = Integer.toString((int)(Math.random()*(r + 1 - l)+l));
			temp = x;
			if(x.contains("-")) x = x.substring(1);
			if(x.length() == 1) {
				System.out.println(x);
				System.exit(0);
			}
			else if(x.length() == 2) {
				if(!x.substring(0, 1).equals(x.substring(1, 2))) {
					System.out.println(x);
					System.exit(0);
				}
			}
			else if(!x.substring(1).contains(x.substring(0, 1)) && x.length() != 1 && x.length() != 2) {
				for(int j = 1; j < x.length(); j++) {
					x = temp.substring(0, j) + temp.substring(j + 1);
					if(x.contains(temp.substring(j, j + 1))) {
						break;
					}
					if(j == x.length() - 1) {
						System.out.println(temp);
						System.exit(0);
					}
				}
			}
			tally++;
			if(tally == r - l + 1) {
				System.out.println(-1);
				break;
			}
		}
		scan.close();
	}
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int l = s.nextInt();
        int r = s.nextInt();
        for (int i = l; i <= r; i++) {
            if (a(i)){
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
    }
    static boolean a (int n){
        int [] col = new int [10];
        while (n != 0){
            col[n % 10] ++;
            n /= 10;
        }
        for (int i = 0; i < 10; i++) {
            if (col[i] > 1) return false;
        }
        return true;
    }
    class Pair {
        int first;
        int second;

        Pair(int x, int y) {
            this.first = x;
            this.second = y;
        }
    }
}

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.lang.Math;

public class Main{
	public static boolean distinctDigits(int n) {
		boolean[] digits = new boolean[10];
		while(n>0) {
			if(digits[n%10])
				return false;
			digits[n%10] = true;
			n = n/10;
		}
		return true;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = 1;
		int l = sc.nextInt(), r = sc.nextInt();
		boolean possible = false;
		while(l<=r && !possible) {
			if(distinctDigits(l)) {
				possible = true;
				System.out.println(l);
				break;
			}
			l++;
		}
		if(!possible)
			System.out.println(-1);
		sc.close();
	}
}

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class DistinctDigits {

    static int checkerdigit(int T1, int T2) {

        int r = 0;

        String st1;
        for (int num = T1;num<=T2;num++) {
            st1 = num + "" ;
            ArrayList<Integer> map = new ArrayList<>();
            for (int i = 0; i < st1.length(); i++) {
                int temp = Character.getNumericValue(st1.charAt(i));

                if (map.size() == 0) {

                    map.add(temp);
                } else {

                    if (!map.contains(temp)) {
                        map.add(temp);
                    } else {
                        while (map.contains(temp)) {
                            temp = temp + 1;

                        }
                        if (temp <= 9) {
                            map.add(temp);
                        } else {
                            map.add(-1);
                        }
                    }

                }
            }
            if ( !map.contains(-1)) {
                String res = "";
                for (int i = 0; i < map.size(); i++)
                    res = res + map.get(i);
                int renu = Integer.parseInt(res);
                return(renu);
            }
        }
        return -1 ;
    }
    public static void main(String args[]){
            Scanner s = new Scanner(System.in) ;

            int T1 = s.nextInt() ;
            int T2 = s.nextInt() ;

        System.out.println(checkerdigit(T1,T2)) ;

    }
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class JavaApplication72 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n1, n2;
        n1 = input.nextInt();
        n2 = input.nextInt();
        String num1;
        int j;
        for ( j = n1 + 1; j < n2; j++) {
            num1 = String.valueOf(j);
            //System.out.println(num1);
            int arr[] = new int[num1.length()];

            for (int c = 0; c < num1.length(); c++) {
                arr[c] = Character.getNumericValue(num1.charAt(c));
            }
            boolean f=diff(arr);
            if(f){
                System.out.println(j);
                break;
            }
        }
        if(j==n2){
            System.out.println(-1);
        }
    }

    public static boolean diff(int arr[]) {
        //System.out.println(Arrays.toString(arr));
        for (int i = 0; i < arr.length-1; i++) {
                for (int z = i + 1; z < arr.length; z++) {
                    if ((arr[i] == arr[z]) && (i!=z)) {
                        return false;
                    }
                }
            }
           return true;
    }

}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Sheel Nidhi Pandey
 *
 */
 public class DistinctDigits {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int l=sc.nextInt();
		int r=sc.nextInt();
		int number;
		int flag=0;

		while(l<r)
		{
			number=l;
			boolean visited[]=new boolean[r];
			Arrays.fill(visited, false);
			while(number!=0)
			{
				if(visited[number%10])
					break;
				visited[number%10]=true;
				number=number/10;
			}
		if(number ==0)
		{
			System.out.println(l);
			flag=1;
			break;
		}
			l++;
		}
		if(flag==0){
			System.out.println("-1");
		}
	}
	}

import java.util.*;
public class Distinct {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int l=0,r=0,x=0;
        l=sc.nextInt();
        r=sc.nextInt();
        int A[]= new int [100];
        for(int i = l+1;i<r;i++){
            if(Check(i))
                x=i;
                break;
        }
        System.out.println(x);
    }
    public static boolean Check(int x){
        int i = 0,flag=0;
        int A[] = new int[x];
        while(x!=0){
            A[i++] = x%10;
            x=x/10;
        }
        for(int j = 0;j<i;j++){
            for(int k = j+1;k<i;k++){
                if(A[j]==A[k])
                    flag=1;
            }
        }
        if(flag==1)
            return true;
        else
            return false;
    }
}

import java.util.*;
import java.io.*;

public class problemA {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

        int l = in.nextInt();
        int r = in.nextInt();

        in.close();

        boolean found = false;

        int x = r + 1;

        for (int i = l + 1; i < r && !found; i++) {
            String number = String.valueOf(i);
            int[] counter = new int[9];
            boolean noWork = false;
            for (int j = 0; j < number.length() && !noWork; j++) {
                counter[Integer.parseInt(String.valueOf(number.charAt(j)))] = counter[Integer.parseInt(String.valueOf(number.charAt(j)))] + 1;
                if (counter[Integer.parseInt(String.valueOf(number.charAt(j)))] > 1) {
                    noWork = true;
                }
            }
            if (!noWork) {
                found = true;
            }
        }

        if (!found) {
            System.out.println(-1);
        } else {
            System.out.println(x);
        }

    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;

//import for Scanner and other utility classes
import java.util.*;

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

public class Main {
    public static void main(String args[] ) throws Exception {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer stt;
        stt=new StringTokenizer(br.readLine());
        int l=Integer.parseInt(stt.nextToken()), r=Integer.parseInt(stt.nextToken());
        boolean bool=true;
        int prin=0;
        for(int i=l; i<r && bool==true; i++){
            String s=Integer.toString(i);
            boolean bool2=true, bool3=true;
            for(int j=0; j<s.length()-1 && bool2==true; j++){
                String temp=s.substring(j, j+1);
                //boolean bool3=true;
                for(int k=j+1; k<s.length() && bool3==true; k++){
                    if(temp.equals(s.substring(k, k+1))){
                        bool3=false;
                    }
                }
                if(bool3==false){
                    bool2=false;
                }
            }
            if(bool2==true){
                bool=false; prin=i;
            }
        }
        if(bool==true){
            System.out.println(-1);
        }
        else{
            System.out.println(prin);
        }
        return;
    }
}

import java.util.*;
import java.math.*;

public class DistinctDigits{

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int l = sc.nextInt(), r = sc.nextInt();
	boolean foo = false;

	while(l++ <= r){
		int num = l;
		Set<Integer> set = new HashSet<>();

		while(num > 0){
			int x = num%10;
			num = num/10;
			set.add(x);
		}
		if(set.size() == (int)(Math.log10(l)+1)){
			foo = true;
			break;
		}
	}
	if(foo)
		System.out.println(l);
	else
		System.out.println(-1);
}
}

    import java.util.*;

    public class test{
        public static void main(String args[]){
            Scanner sc=new Scanner(System.in);
            int arr[]=new int[10];
                int l=sc.nextInt();
                int r=sc.nextInt();
                int i;
                for(i=l;i<=r;i++){
                    int n=i;
                    Arrays.fill(arr,0);
                    while(n!=0){
                        arr[n%10]++;
                        n=n/10;
                    }
                    int k;
                    for(k=0;k<=9;k++)
                        if(arr[k]!=1)
                            break;
                    if(k==10){
                        System.out.print(i);
                        break;
                }
            }

        }
    }

  import java.io.*;
import java.util.*;
import java.lang.*;

    public class d {
    	public static void main (String[] args) {
    	PrintWriter pw=new PrintWriter(System.out);
    	Scanner sc=new Scanner(System.in);
    	  //int n=sc.nextInt();
    	  ArrayList<Integer> a1=new ArrayList<>();
             String s=sc.next();
             int r1=sc.nextInt();
      /* int[] a3=new int[10];
  for(int i=0;i<s.length())
 a[a1.get(i)]++;*/
int v=(int)s.charAt(0)-48;
             a1.add(v);
             int max=v;
            // if(s.length()<=10){
           for(int i=1;i<s.length();i++){
                v=(int)s.charAt(i)-'0';
               if(!a1.contains(v)){
                   a1.add(v);
                   max=v;
               }
               else
               {   //max++;
                   int f1=0;
               for(int j=max+1;j<10;j++){
                       max=j;
                        f1=1;
                   if(!a1.contains(j))
                        break;
                   }
                   if(f1==1)
                   a1.add(max);
                   else
                   a1.add(9);
               }
           }
//}
           int[] a=new int[10];
           int r=0,f=0;
           int i1=a1.size()-1;
          for(int i=0;i<a1.size();i++){
              a[a1.get(i)]++;
              r+=a1.get(i)*(Math.pow(10,i1));
              i1--;
          }
for(int i=0;i<10;i++)
   if(a[i]>1)
    f=1;
          if(r<=r1&&f!=1)
           pw.println(r);
           else
           pw.print(-1);
    	  pw.close();
    	}
    }

import java.util.Scanner;

public class Main {

    static boolean isDiff(int n)
    {

        boolean arr[]=new boolean[10];
        for (int i = 0; i < 10; i++)
            arr[i] = false;

        while (n > 0)
        {
            int digit = n % 10;

            if (arr[digit])
                return false;

            arr[digit] = true;

            n = n / 10;
        }
        return true;
    }

    public static void main (String[] args)
    {
        int l, x = -1, r;

        boolean status = false;

        Scanner scanner = new Scanner(System.in);
        l = scanner.nextInt();
        r = scanner.nextInt();

        if(1<=l && l <= r)
        {
            if(l<=r && r<= 100000){
                for (int i = l; i < r; i++){
                    if(isDiff(i)){
                        status = true;
                        x = i;
                        break;
                    }
                    else {
                        status = false;
                    }
                }
            }
        }

        if(status){
            System.out.println(x);
        }
        else{
            System.out.println("-1");
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tori Karaage
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        private int[] digits = new int[10];

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int l = in.nextInt(), r = in.nextInt();
            boolean found = false;
            for (int i = l; i < r; i++) {
                char[] c = String.valueOf(i).toCharArray();
                if (unique(c)) {
                    out.print(number(c));
                    found = true;
                    break;
                }
            }
            if (!found)
                out.print(-1);
        }

        private int number(char[] c) {
            StringBuilder s = new StringBuilder();
            for (int i = 0; i < c.length; i++) {
                s.append(c[i]);
            }
            String number = s.toString();
            return Integer.valueOf(number);
        }

        private boolean unique(char[] c) {
            for (int j = 0; j < c.length; j++) {
                digits[Integer.parseInt(String.valueOf(c[j]))]++;
                if (digits[Integer.parseInt(String.valueOf(c[j]))] == 2) {
                    for (int i = 0; i < 10; i++) {
                        digits[i] = 0;
                    }
                    return false;
                }

            }
            for (int i = 0; i < 10; i++) {
                digits[i] = 0;
            }
            return true;
        }

    }
}

import java.util.HashSet;
import java.util.Scanner;

public class DistinctDigits {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int l=scan.nextInt();
		int len=String.valueOf(l).length();
		int r=scan.nextInt();
		HashSet hs=new HashSet();
		for(int i=l+1;i<r;i++) {
			int c=i;
			while(c!=0) {
				int a=c%10;
				hs.add(a);
				c=c/10;
			}
			if(hs.size()==len) {
				String s=String.valueOf(i);
				System.out.println(s);
				break;
			}
			else hs.clear();
		}
		if(l>99999 || r>99999) System.out.println(-1);
	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.util.Set;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Rb_wahid
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        ADistinctDigits solver = new ADistinctDigits();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADistinctDigits {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int l = in.nextInt();
            int r = in.nextInt();
            Set<Integer> set = new HashSet<>();
            int value = 0;
            boolean flag = false;
            for (int i = l; i <= r; i++) {
                set = new HashSet<>();
                value = i;
                while (value != 0) {
                    set.add(value % 10);
                    value /= 10;
                }
                if (set.size() == String.valueOf(i).length()) {
                    for (int k : set)
                        out.print(k);
                    out.println();
                    flag = true;
                    break;
                }
            }
            if (!flag)
                out.println(-1);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void print(int i) {
            writer.print(i);
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class comp
{
    private static boolean help(int n){
        String s=String.valueOf(n);
        Set<Character> ss=new HashSet<>();
        for(char c:s.toCharArray()){
            ss.add(c);
        }
        return ss.size()==s.length();
    }
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		for(int i=a;i<=b;i++){
		    if(help(i)){
		        System.out.println(i);
		        break;
		    }
		}
	}
}

import java.util.HashSet;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {

		//Input de consola

		Scanner sc = new Scanner(System.in);

		String[] s =sc.nextLine().split(" ");
		int l = Integer.parseInt(s[0]);
		int r = Integer.parseInt(s[1]);

		//Programa

		HashSet<String> hs;
		boolean found = false;

		for(int i=l+1; i<r; i++) {
			hs = new HashSet<String>();
			s = String.valueOf(i).split("");
			for(int j=0; j<s.length; j++) {
				hs.add(s[j]);
			}
			if(hs.size()==s.length) {
				System.out.println(i);
				found = true;
				break;
			}
		}

		if(!found) {
			System.out.println(-1);
		}

	}

}

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class A1228_Distinct {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int l = scanner.nextInt(), r = scanner.nextInt();
        int ans = -1;
        for (int i = l; i <= r; i++) {
            Set<Integer> digits = new HashSet<>();
            String Sl = "" + i;
            for (int j = 0; j < Sl.length(); j++) {
                digits.add(Integer.parseInt("" + Sl.charAt(j)));
            }
            if (digits.size() == Sl.length() && l != r) {
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }
}

import java.util.*;
import java.lang.*;

public class Solution{

static void printUnique(int l, int r)
    {
        // Start traversing the numbers
        for (int i=l ; i<=r ; i++)
        {
            int num = i;
            boolean visited[] = new boolean[10];

            // Find digits and maintain its hash
            while (num != 0)
            {
                // if a digit occcurs more than 1 time
                // then break
                if (visited[num % 10])
                    break;

                visited[num%10] = true;

                num = num/10;
            }

            // num will be 0 only when above loop
            // doesn't get break that means the
            // number is unique so print it.
            if (num == 0){
                System.out.print(i + " ");
                return;
            }
            else{
                 System.out.print("-1");
                 break;
            }
        }
    }
    public static void main(String args[])
    {
        Scanner ad = new Scanner(System.in);
        int l = ad.nextInt();
        int r = ad.nextInt();
        printUnique(l, r);
    }

}

import java.util.*;
public class solution{
    public static void main(String args[])
	{
		Scanner s=new Scanner(System.in);
		int l=s.nextInt(),r=s.nextInt();

		for (int i=l ; i<=r ; i++)
        {
            int num = i;
            boolean visited[] = new boolean[10];

            while (num != 0)
            {
                if (visited[num % 10])
                    break;

                visited[num%10] = true;

                num = num/10;
            }

            if (num == 0){
                System.out.print(i + " ");
                break;}
        }
		System.out.print("-1");

	}
}

import java.util.Scanner;

public class DistinctDigits {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int l = scan.nextInt();
		int r = scan.nextInt();
		String x = "";
		int tally = 0;
		String temp = "";
		for(int i = 0; i <= r - l + 1; i++) {
			x = Integer.toString((int)(Math.random()*(r + 1 - l)+l));
			temp = x;
			if(!x.substring(1).contains(x.substring(0, 1))) {
				for(int j = 1; j < x.length(); j++) {
					x = temp.substring(0, j) + temp.substring(j + 1);
					if(x.contains(temp.substring(j, j + 1))) {
						break;
					}
					if(j == x.length() - 1) {
						System.out.println(temp);
						System.exit(0);
					}
				}
			}
			tally++;
			if(tally == r - l + 1) {
				System.out.println(-1);
				break;
			}
		}

		scan.close();
	}
}

import java.io.*;
import java.util.*;

public class Main
{
	static class Reader
	{
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader()
		{
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException
		{
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException
		{
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1)
			{
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException
		{
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
			{
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException
		{
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException
		{
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');

			if (c == '.')
			{
				while ((c = read()) >= '0' && c <= '9')
				{
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException
		{
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException
		{
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException
		{
			if (din == null)
				return;
			din.close();
		}
	}

	public static void main(String[] args) throws IOException
	{
		Reader sc = new Reader();
		int l = sc.nextInt();
		int r = sc.nextInt();
		String s1 = "";
		while (l < r) {
			Set<Character> set = new HashSet<Character>();
			StringBuilder s = new StringBuilder(String.valueOf(l));
			for (int i = 0; i < s.length(); i++) {
				set.add(s.charAt(i));
			}
			//System.out.println(set);
			if (set.size() == s.length()) {
			    s1 = s.toString();
				break;
			}
			l++;
		}
		if (s1.length() == 0) {
		    System.out.println(-1);
		}
		else {
		    System.out.println(s1);
		}
	}
}

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {

     Scanner input = new Scanner(System.in);
     int l = input.nextInt();
     int r = input.nextInt();

     while(l != r){
         boolean [] taken = new boolean[10];
         boolean ok = true;
         l++;
         String s = l + "";
         //Check
         for(int i = 0 ; i < s.length() ; i++)
             if(!taken[Integer.parseInt(s.charAt(i) + "")])
                  taken[Integer.parseInt(s.charAt(i) + "")] = true;
             else{
                 ok = false;
                 break;
             }

           if(ok){
               System.out.println(l);
               System.exit(0);
            }
           }
             System.out.println(-1);
    }
}

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
	    try (Scanner sc = new Scanner(System.in)){
            int l = sc.nextInt();
            int r = sc.nextInt();
            for (int i = l; i < r; i++){
                if (checkDifferentDigits(i)){
                    System.out.println(i);
                    return;
                }
            }
            System.out.println(-1);
        } catch (Exception e){
	        throw new IllegalStateException(e);
        }
    }

    public static boolean checkDifferentDigits(int number){
        String digits = String.valueOf(number);
        Set<Character> characterSet = new HashSet<>();
        for (int i = 0; i < digits.length(); i++){
            if (characterSet.contains(digits.charAt(i)))
                return false;
            else
                characterSet.add(digits.charAt(i));
        }
        return true;
    }
}

import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int     l = in.nextInt(),
                r = in.nextInt();
        String s;
        boolean flag = false;
        for (int i = l; i <= r; i++) {
            s = Integer.toString(i);
            char a[] = s.toCharArray();
            Arrays.sort(a);
            for (int j = 0; j < s.length()-1; j++) {
                if (a[j] == a[j+1]) {
                    break;
                }else if (j + 1 == s.length() - 1){
                    flag = true;
                    System.out.println(i);
                    break;
                }
            }
            if (flag) break;
        }
        if (!flag) System.out.println(-1);
    }
}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Optional;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {

    static final long MOD = (long) (1e9 + 7);
    private static PrintWriter out;

    public static void main(String[] args) throws FileNotFoundException {

        // Input from file
        // File inputFile = new File("JavaFile.txt");
        // File outputFile = new File("JavaOutputFile.txt");
        // FileReader fileReader = new FileReader(inputFile);
        // Here it ends

        MyScanner sc = new MyScanner();
        // MyScanner sc = new MyScanner(fileReader);

        out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console
        // out = new PrintWriter(new PrintStream(outputFile)); // Output to file

        getAns(sc);

        out.close();
    }

    /*
     *Don't use builtin function (Math.ceil)
     */

    private static void mprintln(Object... ar) {
        for (Object i : ar) {
            out.print(i + " ");
        }
        out.println();
    }

    private static void mprint(Object... ar) {
        for (Object i : ar) {
            out.print(i + " ");
        }
    }

    private static void getAns(MyScanner sc) {
        int l = sc.ni(), r = sc.ni();
        while (l <= r) {
            if (allIsWell(l)) {
                out.println(l);
                break;
            }
            ++l;
        }
    }

    private static boolean allIsWell(int n) {
        HashSet<Integer> set = new HashSet<>();
        while (n > 0) {
            int cur = n % 10;
            if (set.contains(cur)) return false;
            set.add(cur);
            n /= 10;
        }

        return true;
    }

    static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }

        char nc() {
            return nn().charAt(0);
        }

        int ni() {
            return Integer.parseInt(nn());
        }

        long nl() {
            return Long.parseLong(nn());
        }

        double nd() {
            return Double.parseDouble(nn());
        }

        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = ni();
            }
            return ar;
        }

        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = ni();
            }
            return ar;
        }

        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nl();
            }
            return ar;
        }

        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nl();
            }
            return ar;
        }
    }
}

import java.util.Scanner;

public class JavaApplication70 {
public static int countDistinct(int x){
    boolean [] check = new boolean[10];
    int count = 0;
    while(x != 0){
        int r = x%10;
        check[r] = true;
        x /=10;
    }
    for(int i=0; i<10; i++){
        if(check[i] != false){
            count++;
        }
    }
    return count;
}
public static int CountDigit(int x){
    int count = 0;
    while(x != 0){
        count++;
        x/=10;
    }
    return count;
}

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        while(a < b){
            int x1 = countDistinct(a+1);
            int x2 = CountDigit(a+1);

            if(x1 == x2){
                System.out.println(a+1);
                return;
            }else{
                a++;
            }

        }
        System.out.println(-1);

    }

}

import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
public class digits
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int l,r,i,j,c=1,k; char q;
        l=s.nextInt();
        r=s.nextInt();
        for(i=l+1;i<r;i++)
        {
            String a=Integer.toString(i);
            for(j=0;j<a.length();j++)
            {
                c=0;
                q=a.charAt(j);
                for(k=j+1;k<a.length();k++)
                {
                    if(a.charAt(k)==q)
                    c++;
                }
                if(c>0)
                break;
                }
                if(c==0)
                break;
            }
            if(c==0)
            System.out.println(i);
            else
            System.out.println("-1");
        }
    }

import java.util.*;
import java.io.*;

public class Main {
	public static int countDigits(int n) {
		int count = 0;
		while(n > 0) {
			count++;
			n /= 10;
		}
		return count;
	}
	public static int makeDigits(int n ) {
		String s = "";
		for(int i = 1; i<=n; i++) {
			s += "" + i;
		}
		return Integer.parseInt(s);
	}
	public static void solve(InputReader in) {
		int x = in.readInt();
		int y = in.readInt();
		int n = countDigits(y);
		int ans = makeDigits(n);
		if(ans < 2) {
			System.out.println(x);
		}
		if(y >= ans && x <= ans) {
			System.out.println(ans);
		}
		else System.out.println(-1);
	}

    public static void main(String[] args) {
    	InputReader in = new InputReader(System.in);
    	int t = 1;
    	while(t-- > 0) {
    		solve(in);
    	}
    }
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

     public String next() {
		return readString();
	}

     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int arr[] = new int[10];
        for(int i = a ; i <= b ; i++)
        {

            for(int j = 0 ; j < 10 ; j++)
            {
                arr[j] = 0;
            }

            int copy = i;
            boolean isUnique = true;
            while(copy > 0)
            {
                int digit = copy % 10;

                if(arr[digit] == 0)
                {
                arr[digit]++;
                copy = copy/10;
                }
                else
                {
                    isUnique = false;
                    break;
                }
            }

            if(isUnique)
            {
            System.out.println(i);
            break;
            }
        }
    }
}

import java.util.HashMap;
import java.util.Scanner;
public class Solution
{
	public static boolean same(int n) {
		char[] n1 = String.valueOf(n).toCharArray();
		HashMap<Character, Integer> map = new HashMap<Character, Integer>();
		for(int i = 0;i<n1.length;i++) {
			if(map.containsKey(n1[i])) {
				return false;
			}
			else {
				map.put(n1[i], 1);
			}
		}
		return true;
	}
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int l = sc.nextInt();
    	int r = sc.nextInt();
    	boolean flag = false;
    	while(l <= r) {
    		if(!same(l)) {
    			System.out.println(l);
    			flag = true;
    			break;
    		}
    		else {
    			l+=1;
    		}
    	}
    	if(!flag) {
    		System.out.println(-1);
    	}
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class DistinctDigits {

    	static class FastReader
        {
            BufferedReader br;
            StringTokenizer st;

            public FastReader()
            {
                br = new BufferedReader(new
                         InputStreamReader(System.in));
            }

            String next()
            {
                while (st == null || !st.hasMoreElements())
                {
                    try
                    {
                        st = new StringTokenizer(br.readLine());
                    }
                    catch (IOException  e)
                    {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }

            int nextInt()
            {
                return Integer.parseInt(next());
            }

            long nextLong()
            {
                return Long.parseLong(next());
            }

            double nextDouble()
            {
                return Double.parseDouble(next());
            }

            String nextLine()
            {
                String str = "";
                try
                {
                    str = br.readLine();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                return str;
            }
         }
    	public static void main(String[] args)
        {
        FastReader s=new FastReader();
        int l=s.nextInt();
        int r=s.nextInt();

        for(int i=l;i<=r;i++)
        {
        	int num=i;
        	boolean visited[]=new boolean[10];
        	while(num!=0)
        	{
        	if(visited[num%10])
        		break;
        	visited[num%10]=true;
        	num=num/10;
                }
        	if(num==0)
        	{
        		System.out.println(i);
        		break;
        	}
        	else
        	{
        		System.out.println(-1);
        		break;
        	}
        }
      }
}

import java.util.Scanner;
import java.io.*;

public class DistinctDigits {

    public static void main(String[] args) {

        Scanner readFile = new Scanner(System.in);
        int min = readFile.nextInt();
        int max = readFile.nextInt();

        int tester = min + 1;
        int winner = 50000000;
        while(tester < max){
          if(hasdd(tester)){
            if(tester < winner){
              winner = tester;
            }
          }
          tester++;
        }
        if(winner == 50000000){winner = -1;}
        System.out.println(winner);

}
    public static boolean hasdd(int num){
      int[] holder = {1,1,2,3,4,5,6,7,8,9};
      while(num > 0){
        int test = num%10;
        if(holder[test]==0){return false;}
        holder[test]=0;
        num= num/10;
      }
      return true;
    }
}

import java.util.*;
import java.lang.*;
import java.io.*;
public class Codeforces
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    String copy;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str=br.readLine();
        String[] s=str.split(" ");
        int l=Integer.parseInt(s[0]);
        int r=Integer.parseInt(s[1]);
        l=l+1;
        Set<Integer> digit=new HashSet<Integer>();
        for(;l<r;l++)
        {
            copy=""+l;
            if(copy.length()==1)
            {
                System.out.println(l);
                break;
            }
            for(int i=0;i<copy.length();i++)
            {
                digit.add(Integer.parseInt(""+copy.charAt(i)));
            }
            if(digit.size()==copy.length())
            {
                System.out.println(l);
                break;
            }
            else
            {
                digit.clear();
            }
            if(l==r-1)
            {
                System.out.println(-1);
            }
        }
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class B {

    static boolean check(int n){
        String s=Integer.toString(n);
        TreeSet<Integer> set = new TreeSet<>();
        while (n>0){
            set.add(n%10);n/=10;
        }
        return set.size()==s.length();
    }
    public static void main(String[] args) {
        FastReader scan = new FastReader();

            int l=scan.nextInt();
            int r=scan.nextInt();
            boolean ol=true;
            for (int i=l;i<r;i++){
                if (check(i)){ System.out.println(i);ol=false;
                    break;}
        }
            if (ol) System.out.println("-1");

    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Distinct_Digits {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str[]=br.readLine().split(" ");
        int l=Integer.parseInt(str[0]);
        int r=Integer.parseInt(str[1]);
        int ans=-1;
        for(int i=l+1;i<=r;i++){
            String s=String.valueOf(i);
            int it=0;
            boolean check[]=new boolean[10];
            for(int j=1;j<10&&it<s.length();j++){
                //System.out.println(Character.getNumericValue(s.charAt(it)));
                if(!check[Character.getNumericValue(s.charAt(it))])
                {
                    check[Character.getNumericValue(s.charAt(it))]=true;
                }
                else break;
                it++;
            }
            if(it==s.length()){
                ans=0;
                System.out.println(i);
                break;
            }
        }
        if(ans==-1)
            System.out.println(ans);
    }
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Sheel Nidhi Pandey
 *
 */
 public class DistinctDigits {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int l=sc.nextInt();
		int r=sc.nextInt();
		int number;
		int flag=0;

		while(l<r)
		{
			number=l;
			boolean visited[]=new boolean[r];
			Arrays.fill(visited, false);
			while(number!=0)
			{
				if(visited[number%10])
					break;
				visited[number%10]=true;
				number=number/10;
			}
		if(number ==0)
		{
			System.out.println(l);
			flag=1;
			break;
		}
			l++;
		}
		if(flag==0){
			System.out.println("-1");
		}
	}
	}

import java.util.*;
import java.io.*;

public class test1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().trim().split(" ");
        String n = s[0];
        String m = s[1];
        boolean flag = false;
        for(int i=Integer.parseInt(n);i<Integer.parseInt(m);i++){
            if(check(i)){
                System.out.print(i);
                flag = true;
                break;
            }

        }
        if(!flag)
            System.out.println(-1);
    }

    static boolean check(int num){
        ArrayList<Character> list = new ArrayList<>();
        HashSet<Character> set = new HashSet<>();
        String h = ""+num;
        for(int i=0;i<h.length();i++){
            list.add(h.charAt(i));
        }
        for(int i=0;i<h.length();i++){
            set.add(h.charAt(i));
        }
        if(list.size()==set.size())
            return true;
        else
            return false;
    }
}

/*
 * Remember a 6.89 student can know more than a 10.0 student.
 * Grades don't determine intelligence, they test obedience.
 * I Never Give Up.
 * I will become Candidate Master today.
 * I will defeat Saurabh Anand.
 * Skills are Cheap,Passion is Priceless.
 */
import java.util.*;
import java.util.Map.Entry;
import java.io.*;

import static java.lang.System.out;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class ContestMain{
	private static Reader in=new Reader();
	private static StringBuilder ans=new StringBuilder();
	private static long MOD=(long)1e9+7;
	private static long INF=(long)1e12;
	private static final int N=(int) (1e5+7); // 1e5+7
    private static final double EPS=1e-9;
    private static final int LIM=26;
    private static final double PI=3.1415;
//    private static ArrayList<Integer> v[]=new ArrayList[N];
//    private static int color[]=new int[N];
	private static boolean mark[]=new boolean[N];
//    private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    private static ArrayList<Pair> v[]=new ArrayList[N];
    private static ArrayList<Pair> vrev[]=new ArrayList[N];
	private static long powmod(long x,long n){
		if(n==0||x==0)
			return 1;
		else if(n%2==0)
			return(powmod((x*x)%MOD,n/2));
		else
			return (x*(powmod((x*x)%MOD,(n-1)/2)))%MOD;
	}
	private static void shuffle(long[] arr){
		for(int i=arr.length-1;i>=2;i--){
			int x=new Random().nextInt(i-1);
			long temp=arr[x];
			arr[x]=arr[i];
			arr[i]=temp;
		}
	}
	private static void shuffle(int[] arr){
		for(int i=arr.length-1;i>=2;i--){
			int x=new Random().nextInt(i-1);
			int temp=arr[x];
			arr[x]=arr[i];
			arr[i]=temp;
		}
	}
    private static long gcd(long a, long b){
        if(b==0)return a;
        return gcd(b,a%b);
    }
//    private static boolean check(int x,int y){
//        if((x>=0&&x<n)&&(y>=0&&y<m)&&mat[x][y]!='X'&&!visited[x][y])return true;
//        return false;
//    }
    public static boolean check(int num){
    	HashSet<Integer> set=new HashSet();
    	int mod;
    	while(num>0){
    		mod=num%10;
    		num/=10;
    		if(set.contains(mod))return false;
    		set.add(mod);
    	}
    	return true;
    }
	public static void main(String[] args) throws IOException{
		int l=in.nextInt();
		int r=in.nextInt();
		for(int i=l;i<r;i++){
			if(check(i)){pn(i);return;}
		}
		pn(-1);
	}
	static class Pair<T> implements Comparable<Pair>{
		int l;
		long r;
		Pair(){
			l=0;
			r=0;
		}
		Pair(int k,long v){
			l=k;
			r=v;
		}
		@Override
		public int compareTo(Pair o){
			return (int)(r-o.r);
		}
		// Fenwick tree question comparator
//        @Override
//        public int compareTo(Pair o) {
//            if(o.r!=r)return (int) (r-o.r);
//            else return (int)(l-o.l);
//        }
	}
	//Reader Class
	static class Reader{
		BufferedReader br;
		StringTokenizer st;
		public Reader(){br=new BufferedReader(new InputStreamReader(System.in));}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st=new StringTokenizer(br.readLine());
				}catch(IOException e){e.printStackTrace();}
			}
			return st.nextToken();
		}
		int nextInt(){return Integer.parseInt(next());}
		long nextLong(){return Long.parseLong(next());}
		double nextDouble(){return Double.parseDouble(next());}
		String nextLine(){
			String str="";
			try{
				str=br.readLine();
			}catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
	}
	//Printer Methods
	static void pn(Object o){out.print(o);}
	static void pln(Object o){out.println(o);}
	static void pln(){out.println();}
	//Appenders
	static void app(Object o){ans.append(o);}
}

    import java.util.*;

    public class test{
        public static void main(String args[]){
            Scanner sc=new Scanner(System.in);
            int arr[]=new int[10];
                int l=sc.nextInt();
                int r=sc.nextInt();
                int i;
                for(i=l;i<=r;i++){
                    int n=i;
                    Arrays.fill(arr,0);
                    while(n!=0){
                        arr[n%10]++;
                        n=n/10;
                    }
                    int k;
                    for(k=0;k<=9;k++)
                        if(arr[k]>1)
                            break;
                    if(k==10){
                        System.out.print(i);
                        break;
                }
            }

        }
    }

import java.util.*;
import java.io.*;

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().trim().split(" ");
        String n = s[0];
        String m = s[1];
        boolean flag = false;
        for(int i=Integer.parseInt(n);i<Integer.parseInt(m);i++){
            if(check(i)){
                System.out.print(i+" ");
                flag = true;
                break;
            }

        }
        if(!flag)
            System.out.print(-1);
    }

    static boolean check(int num){
        ArrayList<Character> list = new ArrayList<>();
        HashSet<Character> set = new HashSet<>();
        String h = ""+num;
        for(int i=0;i<h.length();i++){
            list.add(h.charAt(i));
        }
        for(int i=0;i<h.length();i++){
            set.add(h.charAt(i));
        }
        if(list.size()==set.size())
            return true;
        else
            return false;
    }
}

import java.util.*;

/**
 *
 * @author Lenovo
 */
public class JavaApplication2 {

    public static void main(String[] args) {

        int l,r;
		Scanner in=new Scanner(System.in);
		l=in.nextInt();
		r=in.nextInt();
		int ans=-1;
		String x;
		for(int i=l+1;i<r;i++){x=Integer.toString(i); if(x.length()==x.chars().distinct().count()){ans=i;break;}}

	    System.out.println(ans);

    }

    }

import java.util.Arrays;
import java.util.Scanner;

public class CodeForces2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong(); long r = sc.nextLong(); String s;
        label1: for (long i = l; i <= r; i++) {
            s = i+"";
            char arr[] = s.toCharArray();
            Arrays.sort(arr);
               for (int j = 0; j < arr.length-1; j++) {
                if(arr[j] == arr[j+1]) break;
                   else if (arr[j] != arr[j + 1] && j == arr.length - 2) {
                       System.out.println(i);
                       return;
                   }
                }
        }
        System.out.println("-1");
    }
}

import java.util.Scanner;
public class A {
    public static boolean fanc(String str) {
        for (int j = 0; j < str.length() - 1; j++) {
            for (int k = j + 1; k < str.length(); k++) {
                if (str.charAt(j) == str.charAt(k)) {
                    return false;
                }
            }
        }
        return true;
    }
    public static void main(String...args) {
        Scanner s = new Scanner(System.in);
        int a, b;
        a = s.nextInt();
        b = s.nextInt();

        for (int i = a; i <= b; i++) {
            String str = Integer.toString(i);
            boolean flag = fanc(str);
            if (flag) {
               System.out.println(i);
            } else if (i == b && !flag) {
                System.out.println(-1);
            }
        }
    }
}

import java.util.*;
import java.io.*;

public class Main {
	public static int countDigits(int n) {
		int count = 0;
		while(n > 0) {
			count++;
			n /= 10;
		}
		return count;
	}
	public static int makeDigits(int n ) {
		String s = "";
		for(int i = 1; i<=n; i++) {
			s += "" + i;
		}
		return Integer.parseInt(s);
	}
	public static void solve(InputReader in) {
		int x = in.readInt();
		int y = in.readInt();
		int n = countDigits(y);
		int ans = makeDigits(n);
		if(ans < 2) {
			System.out.println(x);
		}
		else if(y >= ans && x <= ans) {
			System.out.println(ans);
		}
		else System.out.println(-1);
	}

    public static void main(String[] args) {
    	InputReader in = new InputReader(System.in);
    	int t = 1;
    	while(t-- > 0) {
    		solve(in);
    	}
    }
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

     public String next() {
		return readString();
	}

     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

import java.util.Scanner;

public class DistinctDigit {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int l = scan.nextInt();
		int r = scan.nextInt();
		String x = "";
		int tally = 0;
		String temp = "";
		for(int i = 0; i <= r - l + 1; i++) {
			x = Integer.toString((int)(Math.random()*(r + 1 - l)+l));
			temp = x;
			if(!x.substring(1).contains(x.substring(0, 1))) {
				for(int j = 1; j < x.length(); j++) {
					x = temp.substring(0, j) + temp.substring(j + 1);
					if(x.contains(temp.substring(j, j + 1))) {
						break;
					}
					if(j == x.length() - 1) {
						System.out.println(temp);
						System.exit(0);
					}
				}
			}
			tally++;
			if(tally == r - l + 1) {
				System.out.println(-1);
				break;
			}
		}

		scan.close();
	}
}

import java.util.HashSet;
import java.util.Scanner;

public class DistinctDigits {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int l=scan.nextInt();
		int r=scan.nextInt();
		int len1=String.valueOf(l).length();
		int len=String.valueOf(r).length();
		HashSet hs=new HashSet();
		for(int i=l;i<=r;i++) {
			int c=i;
			while(c!=0) {
				int a=c%10;
				hs.add(a);
				c=c/10;
			}
			if(hs.size()==len || hs.size()==len1) {
				String s=String.valueOf(i);
				System.out.println(s);
				break;
			}
			else hs.clear();
		}
		if(hs.size()!=len && hs.size()!=len1) System.out.println(-1);
	}

}

/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;

public class GFG {
	public static void main (String[] args) {

	    	Scanner sc = new Scanner(System.in);

		long l =sc.nextInt();

		long r = sc.nextInt();

		long num = l;
		 long ans  =0;

		        for(long i=l;i<=r;i++){

		            if(check(i)){
		                ans = i;
		                break;

		            }

		        }
		        if(ans !=0){
		        System.out.println(num);
		        }else{
		          System.out.println(-1);
		        }

		    }

		    public static boolean check(long x){
		        long digit = 0;
		        HashSet<Long> set = new HashSet<>();
		        	while( x>0){
	                	digit = x%10;

	                	if(set.contains(digit) && set.size() > 0){
	                	    return false;

	                	}else{
	                	    set.add(digit);
	                	}

	                 	x = x/10;
		    }
		    return true;

		    }

}

import java.util.HashSet;
import java.util.Scanner;

public class DistinctDigit {
    static boolean checkUniq(int n)
    {
        int count=0;
        HashSet<Integer> set=new HashSet<Integer>();
        while(n>0)
        {
            set.add(n%10);
            count++;
            n/=10;
        }
        System.out.println("coun="+count);
        if(set.size()==count)
            return true;
        return false;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int l=sc.nextInt();
        int r=sc.nextInt();
        int i;
        for(i=l;i<=r;i++)
        {
            if(checkUniq(i)) {
                System.out.println(i);
                break;
            }
        }
        if(i-1==r)
            System.out.println(-1);

    }
}

import java.util.HashSet;
import java.util.Scanner;

public class DistinctDigits {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int l=scan.nextInt();
		int len=String.valueOf(l).length();
		int r=scan.nextInt();
		HashSet hs=new HashSet();
		for(int i=l;i<=r;i++) {
			int c=i;
			while(c!=0) {
				int a=c%10;
				hs.add(a);
				c=c/10;
			}
			if(hs.size()==len) {
				String s=String.valueOf(i);
				System.out.println(s);
				break;
			}
			else hs.clear();
		}
		if(hs.size()!=len) System.out.println(-1);
	}

}

import java.util.Scanner;
import java.util.Vector;

public class Main {
   public static void main(String[] args) {

        Scanner scan=new Scanner(System.in);
        int l=scan.nextInt();
        int r=scan.nextInt();
        boolean b=true;
        int o=l;
        while(r<=1){
             Vector v = new Vector();
            while(o>0){
                v.add(o%10);
                o/=10;
            }
            for(int k=0;k<v.size();k++){
                for(int s=k+1;s<v.size();s++){
                    if(v.get(k)==v.get(s)){
                        b=false;
                        break;
                    }
                if(b==false){
                    break;
                }}
            }
            if(b==true){
                System.out.println(l);
                System.exit(0);
            }
            b=true;
            l++;
            o=l;
        }
        System.out.println("-1");
    }
}

import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

public class r589p1{

    private static InputReader sc;
    private static PrintWriter pw;
    private static TreeSet<Integer> primeSet;

    private static long gcd(long a, long b){ return (b == 0)?a:gcd(b, a%b); }

    private static long lcm(long a, long b){ return (a/gcd(a, b))*b; }

    private static void genPrime(int lim){
        boolean isPrime[] = new boolean[lim+1];
        Arrays.fill(isPrime, true);

        for(int i=2; i<=lim; i++){
            if(isPrime[i]){
                primeSet.add(i);
                for(long j=(long)i*i; j<=lim; j+=i)
                    isPrime[(int)j] = false;
            }
        }
    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        InputReader(InputStream stream) {
            this.stream = stream;
        }

        int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            boolean isSpaceChar(int ch);
        }
    }

    public static void main(String args[]) {
        sc = new InputReader(System.in);
        pw = new PrintWriter(System.out);
        primeSet = new TreeSet<>();

        int t = 1;
        while(t-->0)
            solve();

        pw.flush();
        pw.close();
    }

    private static boolean check(int n){
        HashSet<Integer> set = new HashSet<>();

        while(n!= 0){
            int k = n%10;

            if(set.contains(k))
                return false;
            set.add(k);
        }
        return true;
    }

    private static void solve(){
        int l = sc.nextInt(), r = sc.nextInt();

        int flag = 0;

        while(l <= r){
            if(check(l)) {
                pw.println(l);
                flag = 1;
                break;
            }
            l++;
        }

        if(flag == 0)
            pw.println(-1);
    }
}

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {

     Scanner input = new Scanner(System.in);
     int l = input.nextInt();
     int r = input.nextInt();

     while(l > r){
         boolean [] taken = new boolean[10];
         boolean ok = true;
         l++;
         String s = l + "";
         //Check
         for(int i = 0 ; i < s.length() ; i++)
             if(!taken[Integer.parseInt(s.charAt(i) + "")])
                  taken[Integer.parseInt(s.charAt(i) + "")] = true;
             else{
                 ok = false;
                 break;
             }

           if(ok){
               System.out.println(l);
               System.exit(0);
            }
           }
             System.out.println(-1);
    }
}

import java.util.*;
import java.io.*;

public class DistinctDigits {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(in.readLine());
		int left = Integer.parseInt(st.nextToken());
		int right = Integer.parseInt(st.nextToken());
		int num = -1;
		for(int i = 0; i < 10; ++i) {
			for(int j = 0; j < 10; ++j) {
				if (j == i && (j != 0)) continue;
				for(int k = 0; k < 10; ++k) {
					if ((k == j || k == i) && k != 0) continue;
					for(int l = 0; l < 10; ++l) {
						if ((l == k || l == j || l == i) && l != 0) continue;
						for(int m = 0; m < 10; ++m) {
							if ((m == l || m == k || m == j || m == i) && m != 0) continue;
							int a = i*10000 + j*1000 + k*100 + l*10 + m;
							if(a >= left && a <= right) {
								num = a;
								break;
							}
						}
						if(num > -1) break;
					}
					if(num > -1) break;
				}
				if(num > -1) break;
			}
			if(num > -1) break;
		}
		if(left == 100000)
			out.println(100000);
		else
			out.println(num);
		in.close();
		out.close();
	}
}

import java.util.*;

public class solution{

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int m = sc.nextInt();
		boolean printed = false;
		for(int i = l+1; i < m; i++){
			if(isDistinct(i)){
				System.out.println(i);
				printed = true;
				break;
			}
		}
		if(!printed)System.out.println("-1");
	}

	public static boolean isDistinct(int n){
		Hashtable<Integer, Integer> h = new Hashtable<Integer, Integer>();
		while(n > 0){
			int mod = n % 10;
			if(h.contains(mod)){
				return false;
			}else{
				h.put(mod, mod);
			}
			n /= 10;
		}
		return true;
	}
}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int e = sc.nextInt();
        int x = -1;
        boolean b = true;
        out:
        while(b = true){
           for(int i=s;i<=e;i++){
                    x = i;
                    char[] chars = ("" + x).toCharArray();
                    outerloop:
                    for(int j=0;j<chars.length;j++){
                        for(int k=0; k<j;k++){
                            if(chars[j]==chars[k]){
                                b = true;
                                break outerloop;
                            }
                            else b = false;
                        }
                    }
                    if(b==false){
                        System.out.println(x);
                        break out;
                    }

            }
           if(b == true){
               System.out.println(-1);
               break;
           }
        }
    }
}

import java.util.Scanner;

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int distance = b - a;
        int hello = a;
        boolean minus = false;
        Integer e = new Integer(a);
        String r = e.toString();
        if (r.length() == 1 || a==b) {
            System.out.println(a);
            minus = true;
        } else {
            for (int i = 1; i <= distance && a <= b; i++) {
                hello++;
                Integer str = new Integer(hello);
                String check = str.toString();
                boolean flag = false;
                for (int j = 0; j < check.length() - 1; j++) {
                    for (int k = j + 1; k < check.length(); k++) {
                        if (check.charAt(j) == check.charAt(k)) {
                            flag = true;
                        }
                    }
                }
                if (!flag) {
                    System.out.println(check);
                    minus = true;
                    break;
                }
            }
        }
        if (!minus) {
            System.out.println(-1);
        }

    }
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Sheel Nidhi Pandey
 *
 */
 public class DistinctDigits {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int l=sc.nextInt();
		int r=sc.nextInt();
		int number;
		int flag=0;
		if(l>=10 && r>=10){
		while(l<=r)
		{
			number=l;
			boolean visited[]=new boolean[r+1];
			Arrays.fill(visited, false);
			while(number!=0 )
			{
				if(visited[number%10])
					break;
				visited[number%10]=true;
				 number=number/10;
			}
		if(number ==0 )
		{
			System.out.println(l);
			flag=1;
			break;
		}
			l++;
		}
		}
		if(flag==0){
			System.out.println("-1");
		}
	}
	}

import java.util.*;
import java.io.*;

public class problemA {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

        int l = in.nextInt();
        int r = in.nextInt();

        in.close();

        boolean found = false;

        int x = r + 1;

        for (int i = l + 1; i < r && !found; i++) {
            String number = String.valueOf(i);
            int[] counter = new int[9];
            boolean noWork = false;
            for (int j = 0; j < number.length() && !noWork; j++) {
                counter[Integer.parseInt(String.valueOf(number.charAt(j))) - 1] = counter[Integer.parseInt(String.valueOf(number.charAt(j))) - 1] + 1;
                if (counter[Integer.parseInt(String.valueOf(number.charAt(j))) - 1] > 1) {
                    noWork = true;
                }
            }
            if (!noWork) {
                found = true;
            }
        }

        if (!found) {
            System.out.println(-1);
        } else {
            System.out.println(x);
        }

    }
}

import java.util.HashSet;
import java.util.Scanner;
public class DistinctDigit{

    public static int solve(int ini, int fin){
        String inicial = Integer.toString(ini);

        HashSet <Character> dic = new HashSet<>();

        while (ini != fin){
            ini = ini + 1;

            inicial = Integer.toString(ini);

            for(int i = 0; i < inicial.length(); i++){
                dic.add( inicial.charAt(i));
            }

            if ( dic.size() == inicial.length() ){
                return ini;
            }

        }

        return -1;

    }

    public static void main(String args []){
        Scanner res = new Scanner(System.in);
        int ini = res.nextInt();
        int fin = res.nextInt();

        System.out.println(solve(ini, fin));

    }

}

import java.util.*;

public class A {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r,i,a,b,x;

		a=sc.nextInt();
		b=sc.nextInt();

		for(i=a;i<=b;i++) {
			int sig=0;
			int d[] = new int[10];
			x=i;
			while(x>0)
			{
				r = x%10;
				d[r] = d[r] + 1;
				if(d[r]>1)
				{
					sig  = 1;
					break;
				}
				x=x/10;
			}
			if(sig==0)
			{
				System.out.println(i);
				return;
			}

		}
	}
}

import java.lang.* ;
import java.io.* ;
import java.util.* ;

// A U T H O R : s a n 1 d h y a

public class cf1228A {
	static long Mod1 = 1000000007;

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	/*
	 * public static void sortbyColumn(int arr[][], int col) { // Using built-in
	 * sort function Arrays.sort Arrays.sort(arr, new Comparator<int[]>() {
	 *
	 * @Override // Compare values according to columns public int compare(final
	 * int[] entry1, final int[] entry2) {
	 *
	 * // To sort in descending order revert // the '>' Operator if (entry1[col] >
	 * entry2[col]) return 1; else return -1; } }); // End of function call sort().
	 * }
	 */
/*	public static long binex(long x, long y) {
		x = x % Mod1;
		long ret = 1;
		while (y > 0) {
			if (y % 2 != 0) {
				ret = ret * x % Mod1;
			}
			x = x * x % Mod1;
			y >>= 1;
		}
		return ret;
	}
*/
/*	public static long mplr(long x, long y) {
		long ret = 0;
		while (y != 0) {
			if (y % 2 != 0) {
				ret = (ret + x) % Mod1;
			}
			x = (x + x) % Mod1;
			y >>= 1;
		}
		return ret;
	}
*/
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int l = sc.nextInt();
		int r=sc.nextInt();
		int flag=0;
		int i;
		for(i=l+1;i<r;i++) {
			int a[]=new int[10];
			Arrays.fill(a,0);
			for(int j=i;j>0;j/=10) {
				int d=j%10;
				a[d]++;
			}
			int flag1=0;
			for(int j=0;j<10;j++) {
				if(a[j]>1)
				{
					flag1=1;
					break;
				}
			}
			if(flag1==0)
			{
				flag=1;
				break;
			}
		}
		if(flag==1)
		System.out.println(i);
		else
			System.out.println("-1");
	}
}

    import java.util.*;
    public class test
    {
        public static void main(String args[])
        {
            Scanner sc=new Scanner(System.in);
            int arr[]=new int[10];
                int l=sc.nextInt();
                int r=sc.nextInt();
                int i;
                for(i=l;i<=r;i++)
                {
                    int n=i;
                    Arrays.fill(arr,0);
                    while(n!=0)
                    {
                        arr[n%10]++;
                        n=n/10;
                    }
                    int k;
                    for(k=0;k<=9;k++){
                        if(arr[k]!=1)
                            break;
                    }
                    if(k==10)
                    {
                        System.out.print(i);
                        break;
                    }
                }
                if(i==r+1)
                    System.out.print(-1);
        }
    }

import java.util.*;
public class Solution{
    static boolean distinct(int n)
    {
        boolean arr[]=new boolean[10];
        for (int i = 0; i < 10; i++)
            arr[i] = false;
        while (n > 0)
        {
            int digit = n % 10;
            if(arr[digit])
            return false;
            arr[digit] = true;
            n = n / 10;
        }
        return true;
    }
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        int b=s.nextInt();
        int i;
        for(i=a+1;i<b;i++){
            if(distinct(i)){
                System.out.println(i);
                break;
            }
        }
        if(i==b){
            System.out.println("-1");
        }
        if(a-b<2){
            System.out.println("-1");
        }
    }
}

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int l = console.nextInt(), r = console.nextInt();
        Set<Integer> set = new HashSet<Integer>();
        for (int i = l; i <= r; i++) {
          int temp = i;
          while (temp > 0) {
            set.add(temp % 10);
            temp /= 10;
          }
          if (set.size() != Integer.toString(l).length()) {
            l++;
          } else {
            System.out.println(l);
            return;
          }
        }
        System.out.println(-1);
    }
}

import java.util.HashSet;
import java.util.Scanner;

public class DistinctDigits {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int l=scan.nextInt();
		int r=scan.nextInt();
		int len1=String.valueOf(l).length();
		int len=String.valueOf(r).length();
		HashSet hs=new HashSet();
		for(int i=l;i<=r;i++) {
			int c=i;
			while(c!=0) {
				int a=c%10;
				hs.add(a);
				c=c/10;
			}
			if(hs.size()==len || hs.size()==len1) {
				String s=String.valueOf(i);
				System.out.println(s);
				break;
			}
			else hs.clear();
		}
		if(hs.size()!=len || hs.size()!=len1) System.out.println(-1);
	}

}

import java.util.Scanner;
import java.io.*;

public class DistinctDigits {

    public static void main(String[] args) {

        Scanner readFile = new Scanner(System.in);
        int min = readFile.nextInt();
        int max = readFile.nextInt();

        int tester = min + 1;
        int winner = 50000000;
        while(tester < max){
          if(hasdd(tester)){
            if(tester < winner){
              winner = tester;
            }
          }
          tester++;
        }
        if(winner == 50000000){winner = -1;}
        System.out.println(winner);

}
    public static boolean hasdd(int num){
      int[] holder = {0,1,2,3,4,5,6,7,8,9};
      while(num > 0){
        int test = num%10;
        if(holder[test]==0){return false;}
        holder[test]=0;
        num= num/10;
      }
      return true;
    }
}

import java.util.*;
import java.io.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc= new Scanner(System.in);

        int a=sc.nextInt();
        int b=sc.nextInt();

        while((a++)<=b){
            int count=0;
            int temp=a;
            ArrayList<Integer> ar= new ArrayList<>();
            while(temp>0){
                count++;
                if(!ar.contains(temp%10)){
                    ar.add(temp%10);
                }
                temp=temp/10;
            }
            if(ar.size()==count){
                System.out.println(a);
                return ;
            }

        }
        System.out.println("-1");
    }

}

import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int     l = in.nextInt(),
                r = in.nextInt();
        String s;
        boolean flag = false;
        for (int i = l; i <= r; i++) {
            s = Integer.toString(i);
            char a[] = s.toCharArray();
            Arrays.sort(a);
            for (int j = 0; j < s.length()-1; j++) {
                if (a[j] == a[j+1]) {
                    break;
                }else if (j + 1 == s.length() - 1){
                    flag = true;
                    System.out.println(i);
                    break;
                }
            }
            if (flag) break;
        }
    }
}

import java.util.*;
import java.math.*;

public class DistinctDigits{

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int l = sc.nextInt(), r = sc.nextInt();
	boolean foo = false;

	while(l++ < r){
		int num = l;
		Set<Integer> set = new HashSet<>();

		while(num > 0){
			int x = num%10;
			num = num/10;
			set.add(x);
		}
		if(set.size() == (int)(Math.log10(l)+1)){
			foo = true;
			break;
		}
	}
	if(foo)
		System.out.println(l);
	else
		System.out.println(-1);
}
}

/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;

public class GFG {
	public static void main (String[] args) {

	    	Scanner sc = new Scanner(System.in);

		long l =sc.nextInt();

		long r = sc.nextInt();

		long num = 0;
		 long ans  =0;

		        for(long i=l;i<r;i++){
		             num = i + 1;

		            if(check(num)){
		                ans = num;
		                break;

		            }

		        }
		        if(ans !=0){
		        System.out.println(num);
		        }else{
		          System.out.println(-1);
		        }

		    }

		    public static boolean check(long x){
		        long digit = 0;
		        HashSet<Long> set = new HashSet<>();
		        	while( x>0){
	                	digit = x%10;

	                	if(set.contains(digit)){
	                	    return false;

	                	}else{
	                	    set.add(digit);
	                	}

	                 	x = x/10;
		    }
		    return true;

		    }

}

import java.util.*;
import java.io.*;

public class EjerA5 {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int l,r, flag = 0;

    l = sc.nextInt();
    r = sc.nextInt();
    int temp = l-1;

    for (int i = l; i <= r; i++) {
        System.out.println("Temp: " + temp);
        String tempstr = Integer.toString(temp);
        if (check(tempstr) == false) {
            System.out.println(tempstr);
            flag++;
            break;
        }

    }
        if (flag == 0) {
            System.out.println("-1");
        }

    }

    public static boolean check(CharSequence g) {
        for (int i = 0; i < g.length(); i++) {
            for (int j = i + 1; j < g.length(); j++) {
                if (g.charAt(i) == g.charAt(j)) {
                    return true;
                }
            }
        }
        return false;
    }
}

import java.util.*;
public class Solution{
    static boolean distinct(int n)
    {
        boolean arr[]=new boolean[10];
        for (int i = 0; i < 10; i++)
            arr[i] = false;
        while (n > 0)
        {
            int digit = n % 10;
            if(arr[digit])
            return false;
            arr[digit] = true;
            n = n / 10;
        }
        return true;
    }
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        int b=s.nextInt();
        int i;
        for(i=a+1;i<b;i++){
            if(distinct(i)){
                System.out.println(i);
                break;
            }
        }
        if(i==b+1){
            System.out.println("-1");
        }
    }
}

import java.util.*;
import java.io.*;

public class EjerA5 {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int l,r, flag = 0;

    l = sc.nextInt();
    r = sc.nextInt();
    int temp = l;

    for (int i = l; i < r; i++) {
        temp++;
        String tempstr = Integer.toString(temp);
        if (check(tempstr) == false) {
            System.out.println(tempstr);
            flag++;
            break;
        }

    }
        if (flag == 0) {
            System.out.println("-1");
        }

    }

    public static boolean check(CharSequence g) {
        for (int i = 0; i < g.length(); i++) {
            for (int j = i + 1; j < g.length(); j++) {
                if (g.charAt(i) == g.charAt(j)) {
                    return true;
                }
            }
        }
        return false;
    }
}

import java.util.*;

public class solution{

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int m = sc.nextInt();
		boolean printed = false;
		for(int i = l+1; i <= m; i++){
			if(isDistinct(i)){
				System.out.println(i);
				printed = true;
				break;
			}
		}
		if(!printed)System.out.println("-1");
	}

	public static boolean isDistinct(int n){
		Hashtable<Integer, Integer> h = new Hashtable<Integer, Integer>();
		while(n > 0){
			int mod = n % 10;
			if(h.contains(mod)){
				return false;
			}else{
				h.put(mod, mod);
			}
			n /= 10;
		}
		return true;
	}
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Sheel Nidhi Pandey
 *
 */
 public class DistinctDigits {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int l=sc.nextInt();
		int r=sc.nextInt();
		int number;
		int flag=0;
		if(l>=10 && r>=10){
		while(l<=r)
		{
			number=l;
			boolean visited[]=new boolean[r+1];
			Arrays.fill(visited, false);
			while(number!=0 )
			{
				if(visited[number%10])
					break;
				visited[number%10]=true;
				 number=number/10;
			}
		if(number ==0 )
		{
			System.out.println(l);
			flag=1;
			break;
		}
			l++;
		}
		}
		if(flag==0){
			System.out.println("-1");
		}
	}
	}

import java.util.HashSet;
import java.util.Scanner;

public class DistinctDigits {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int l=scan.nextInt();
		int len=String.valueOf(l).length();
		int r=scan.nextInt();
		HashSet hs=new HashSet();
		for(int i=l+1;i<=r;i++) {
			int c=i;
			while(c!=0) {
				int a=c%10;
				hs.add(a);
				c=c/10;
			}
			if(hs.size()==len) {
				String s=String.valueOf(i);
				System.out.println(s);
				break;
			}
			else hs.clear();
		}
		if(l>99999 || r>99999||hs.size()!=len) System.out.println(-1);
	}

}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Scanner;

@SuppressWarnings("unused")
public class A {
	public  static  Scanner scan = new Scanner(System.in);

	public static void solve () {
		int n=scan.nextInt();
		int r=scan.nextInt();
		String str=Integer.toString(n);
		int c=n;
		for(int i=c;i<=r;i++){
			LinkedHashSet<Integer> h= new LinkedHashSet<Integer>();
			String s=Integer.toString(i);
			//System.out.println(s);
			for(int j=0;j<s.length();j++) {
				String t=""+s.charAt(j);
				h.add(Integer.parseInt(t));
			}
			if(h.size()==str.length()) {
				for (Integer integer : h) {
					System.out.print(integer);
				}
				return;
			}
		}
		System.out.println("-1");

	}

	public static void main(String[] args) {

		solve();
		scan.close();
	}

}

import java.util.Scanner;

public class DistinctDigit {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int l = scan.nextInt();
		int r = scan.nextInt();
		String x = "";
		int tally = 0;
		String temp = "";
		for(int i = 0; i <= r - l + 1; i++) {
			x = Integer.toString((int)(Math.random()*(r + 1 - l)+l));
			temp = x;
			if(!x.substring(1).contains(x.substring(0, 1))) {
				for(int j = 1; j < x.length(); j++) {
					x = temp.substring(0, j) + temp.substring(j + 1);
					if(x.contains(temp.substring(j, j + 1))) {
						break;
					}
					if(j == x.length() - 1) {
						System.out.println(temp);
						System.exit(0);
					}
				}
			}
			tally++;
			if(tally == r - l + 1) {
				System.out.println(-1);
				break;
			}
		}

		scan.close();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Distinct_Digits {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str[]=br.readLine().split(" ");
        int l=Integer.parseInt(str[0]);
        int r=Integer.parseInt(str[1]);
        int ans=-1;
        for(int i=l+1;i<r;i++){
            String s=String.valueOf(i);
            int it=0;
            boolean check[]=new boolean[10];
            for(int j=1;j<10&&it<s.length();j++){
                //System.out.println(Character.getNumericValue(s.charAt(it)));
                if(!check[Character.getNumericValue(s.charAt(it))])
                {
                    check[Character.getNumericValue(s.charAt(it))]=true;
                }
                else break;
                it++;
            }
            if(it==s.length()){
                ans=0;
                System.out.println(i);
                break;
            }
        }
        if(ans==-1)
            System.out.println(ans);
    }
}

import java.util.Scanner;
import java.util.TreeMap;

public class TP {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		boolean flag=false;
		for(int i=n;i<m;i++)
		{
		       TreeMap<Integer,Integer> tm =new TreeMap<>();
		       flag=false;
		       int k=i;
		       //System.out.println("K"+k);
		       while(k>0)
		       {
		              int temp=k%10;
		              if(tm.containsKey(temp))
		              {
		                     flag=true;
		                     break;
		              }
		              tm.put(temp,0);
		              k=k/10;
		       }
		       if(flag==false)
		       {
		              System.out.println(i);
		              break;
		       }
		}
		if(flag==true)
		       System.out.println("-1");
	}
}

import java.util.*;
import java.lang.*;

public class Solution{

static void printUnique(int l, int r)
    {
        // Start traversing the numbers
        for (int i=l ; i<=r ; i++)
        {
            int num = i;
            boolean visited[] = new boolean[10];

            // Find digits and maintain its hash
            while (num != 0)
            {
                // if a digit occcurs more than 1 time
                // then break
                if (visited[num % 10])
                    break;

                visited[num%10] = true;

                num = num/10;
            }

            // num will be 0 only when above loop
            // doesn't get break that means the
            // number is unique so print it.
            if (num == 0){
                System.out.print(i + " ");
                return;
            }
        }
    }
    public static void main(String args[])
    {
        Scanner ad = new Scanner(System.in);
        int l = ad.nextInt();
        int r = ad.nextInt();
        printUnique(l, r);
    }

}

import java.util.*;
import java.math.*;

public class DistinctDigits{

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int l = sc.nextInt(), r = sc.nextInt();
	boolean foo = false;

	while(l++ <= r){
		int num = l;
		Set<Integer> set = new HashSet<>();

		while(num > 0){
			int x = num%10;
			num = num/10;
			set.add(x);
		}
		if(set.size() == (int)(Math.log10(l)+1)){
			foo = true;
			break;
		}
	}
	if(foo)
		System.out.println(l);
	else
		System.out.println(-1);
}
}

import java.util.Scanner;

public class Main {

    static boolean isDiff(int n)
    {

        boolean arr[]=new boolean[10];
        for (int i = 0; i < 10; i++)
            arr[i] = false;

        while (n > 0)
        {
            int digit = n % 10;

            if (arr[digit])
                return false;

            arr[digit] = true;

            n = n / 10;
        }
        return true;
    }

    public static void main (String[] args)
    {
        int l, x = -1, r;

        boolean status = false;

        Scanner scanner = new Scanner(System.in);
        l = scanner.nextInt();
        r = scanner.nextInt();

        for (int i = l; i < r; i++){
            if(isDiff(i)){
                status = true;
                x = i;
                break;
            }
            else {
                status = false;
            }
        }

        if(status){
            System.out.println(x);
        }
        else{
            System.out.println("-1");
        }

    }
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class code17 {

	public static void main (String[] args) {
		//code
		Scanner scn = new Scanner(System.in);
		int l = scn.nextInt();
		int r = scn.nextInt();
		int flag = 0;
		for(int i=l; i<=r; i++) {
			String k = Integer.toString(i);
			HashMap<Character, Integer> map = new HashMap<>();
			for(int j=0; j<k.length(); j++) {
				if(map.containsKey(k.charAt(j)))
					continue;
				if(j==k.length()-1 && !map.containsKey(k.charAt(j))) {
					System.out.println(k);
					flag = 1;
					break;
				}
				if(flag == 1)
					break;
				map.put(k.charAt(j), 1);
			}
		}
		if(flag == 0)
			System.out.println("-1");
	}
}

//comment the next imports before submitting
import java.io.File;
import java.io.PrintStream;
//imports to be deleted ends here

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.StringTokenizer;

//Problem URL here

public class DistinctDigits1228A {

    public static HashSet<Integer> digits = new HashSet<>();

    public static void solve(int a, int b) {

        int val = 0;
        String start = "" + a;

        for (int i = 0; i < start.length(); i++) {
            int d = start.charAt(i) - '0';
            if (digits.contains(d)) {
                if (digits.size() == 10) {
                    System.out.println(-1);
                    return;
                } else {
                    while (++d <= 9) {
                        if (!digits.contains(d)) {
                            val = val * 10 + d;
                            digits.add(d);
                            break;
                        }
                    }
                    if (d > 9) {
                        System.out.println(-1);
                        return;
                    }
                }
            } else {
                val = val * 10 + d;
                digits.add(d);
            }
        }

        if (val >= a && val <= b) {
            System.out.println(val);
        } else {
            System.out.println(-1);
        }

    }

    public static void main(String[] args) throws IOException {

        FastReader reader = new FastReader();

        // int t = reader.nextInt();
        // while (t-- > 0) {
        // int n = reader.nextInt();

        // Integer arr[] = new Integer[n];

        // for (int i = 0; i < n; i++) {
        // arr[i] = reader.nextInt();
        // }

        // Arrays.sort(arr, new Comparator<Integer>() {
        // public int compare(Integer i1, Integer i2) {
        // return i1 - i2;
        // }
        // });

        // System.out.println(Arrays.toString(arr));

        int a = reader.nextInt();
        int b = reader.nextInt();
        solve(a, b);
        // }

    }

    private static void sieveOfEratosthenes(boolean[] arr, int len) {
        for (int j = 2; j * j <= len; j++) {
            if (arr[j]) {
                for (int k = 2; k * j < len; k++) {
                    arr[k * j] = false;
                }
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}