You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard.Initially, you have an empty string. Until you type the whole string, you may perform the following operation:  add a character to the end of the string. Besides, at most once you may perform one additional operation: copy the string and append it to itself.For example, if you have to type string abcabca, you can type it in 7 operations if you type all the characters one by one. However, you can type it in 5 operations if you type the string abc first and then copy it and type the last character.If you have to type string aaaaaaaaa, the best option is to type 4 characters one by one, then copy the string, and then type the remaining character.Print the minimum number of operations you need to type the given string.

The first line of the input containing only one integer number n (1 ≤ n ≤ 100) — the length of the string you have to type. The second line containing the string s consisting of n lowercase Latin letters.

Print one integer number — the minimum number of operations you need to type the given string.

NoteThe first test described in the problem statement.In the second test you can only type all the characters one by one.

#![allow(unused_imports, unused_variables, dead_code, non_snake_case, unused_macros)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;
use std::iter::FromIterator;
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}
macro_rules ! readl { ( $ t : ty ) => { { let s = getline ( ) ; s . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,+ ) => { { let s = getline ( ) ; let mut iter = s . trim ( ) . split ( ' ' ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; }
macro_rules ! readlvec { ( $ t : ty ) => { { let s = getline ( ) ; let iter = s . trim ( ) . split ( ' ' ) ; iter . map ( | x | x . parse ( ) . unwrap ( ) ) . collect ::< Vec <$ t >> ( ) } } }
macro_rules ! mvec { ( $ v : expr , $ s : expr ) => { vec ! [ $ v ; $ s ] } ; ( $ v : expr , $ s : expr , $ ( $ t : expr ) ,* ) => { vec ! [ mvec ! ( $ v , $ ( $ t ) ,* ) ; $ s ] } ; }
macro_rules ! debug { ( $ x : expr ) => { println ! ( "{}: {:?}" , stringify ! ( $ x ) , $ x ) } }
fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display,
{
    for (i, e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}
struct ContestPrinter {
    s: String,
}
impl ContestPrinter {
    fn new() -> ContestPrinter {
        ContestPrinter { s: String::new() }
    }
    fn print<T>(&mut self, x: T)
    where
        T: std::fmt::Display,
    {
        self.s.push_str(format!("{}", x).as_str());
    }
    fn println<T>(&mut self, x: T)
    where
        T: std::fmt::Display,
    {
        self.s.push_str(format!("{}\n", x).as_str());
    }
}
impl std::ops::Drop for ContestPrinter {
    fn drop(&mut self) {
        print!("{}", self.s);
    }
}
static MOD: i64 = 1e9 as i64 + 7;
fn is_max_i64(num: i64) -> bool {
    if num == i64::max_value() {
        true
    } else {
        false
    }
}

fn bfs(graph: &Vec<Vec<usize>>, start: usize) -> Vec<usize> {
    let mut visited: Vec<i32> = vec![-1; graph.len()];
    let mut prev: Vec<usize> = vec![0; graph.len()];
    prev[start] = usize::max_value();
    let mut q: VecDeque<usize> = VecDeque::new();
    visited[start] = 0;
    q.push_back(start);
    while !q.is_empty() {
        let &c_idx = q.front().unwrap();
        let c_cost = visited[c_idx];
        for n_idx in graph[c_idx].iter() {
            let c = visited[*n_idx];
            if c < 0 {
                let n_cost = c_cost + 1;
                visited[*n_idx] = n_cost;
                prev[*n_idx] = c_idx;
                q.push_back(*n_idx);
            }
        }
        q.pop_front();
    }
    prev
}

fn get_path(prev: Vec<usize>, goal: usize) -> Vec<usize> {
    let mut path = Vec::new();
    let mut c = goal;
    while c != usize::max_value() {
        path.push(c);
        c = prev[c];
    }
    path
}

fn main() {
    let mut pr = ContestPrinter::new();
    /*let (N, M, S, T) = readl!(usize, usize, usize, usize);
    let mut g: Vec<Vec<usize>> = vec![Vec::new(); N];
    for i in 0..M {
        let (a, b) = readl!(usize, usize);
        g[a-1].push(b-1);
        g[b-1].push(a-1);
    }

    let path = bfs(&g, S-1);
    let p_nodes = get_path(path, T-1);
    let p_set: HashSet<usize> = HashSet::from_iter(p_nodes.iter().cloned());
    let num = p_nodes.len();
    let mut ans = 0;
    for i in 0..N {
        ans += N - num;
        let mut cnt = 0;
        let on = p_set.contains(&i);
        for j in 0..g[i].len() {
            let idx = g[i][j];
            if on & !p_set.contains(&idx) {
                cnt += 1;
            }
        }
        ans -= cnt;
    }

    pr.println(ans);*/
    let N = readl!(usize);
    let s = readl!(String);

    let mut ans = 0;
    for i in 1..N/2+1 {
        let pr = &s[0..i];
        let co = &s[i..i+i];
        if pr == co { ans = i-1; };
    }

    pr.println(N - ans);
}

use std::io;
use std::cmp::max;

trait Substring {
    fn substring(&self, start: i32, len: i32) -> String;
}

impl Substring for String {

    fn substring(&self, start: i32, len: i32) -> String {
        self.chars().skip(start as usize).take(len as usize).collect()
    }
}

fn main() {

    let mut n: String = String::new();
    let mut inp: String = String::new();

    io::stdin().read_line(&mut n).unwrap();
    io::stdin().read_line(&mut inp).unwrap();

    let n: i32 = n.trim().parse().unwrap();

    let mut ans: Vec<_> = (0..n/2+1).filter(|&i: &i32| -> bool {
        inp.substring(0, i) == inp.substring(i, i)
    }).collect();

    let ans: i32 = ans.pop().unwrap();
    let display: i32 = n - max(ans-1, 0);

    println!("{}", display);
}


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

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

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

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

#[allow(unused_imports)]
use std::io::{BufReader, BufWriter, stdin, stdout, Write};
use std::cmp::{min, max};
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap};

fn check(mut x:i64) -> bool {
	let mut ch = vec![false; 10];
	while x > 0 {
		if ch[(x % 10) as usize] {
			return false;
		}
		ch[(x % 10) as usize] = true;
		x /= 10;
	}
	return true;
}

fn main() {
	let mut inp = my_input::default();
	let out = &mut BufWriter::new(stdout());
	let l:i64 = inp.scan::<i64>();
	let r:i64 = inp.scan::<i64>();
	for i in l..r+1 {
		if check(i) {
			writeln!(out, "{}", i);
			return;
		}
	}
	writeln!(out, "-1");
}

#[derive(Default)]
struct my_input {
	buffer: Vec<String>
}

impl my_input {
	fn scan<T: std::str::FromStr>(&mut self) -> T {
		loop {
			if let Some(token) = self.buffer.pop() {
				return token.parse().ok().expect("Parsing Error");
			}
			let mut s = String::new();
			stdin().read_line(&mut s).expect("Reading Error");
			self.buffer = s.split_whitespace().rev().map(String::from).collect();
		}
	}
}

use std::io::{Read,stdin};

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    let mut tok = buf.split_whitespace();
    let mut get = || tok.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }

    let l = get!(usize);
    let r = get!(usize);

    for x in l ..= r {
        let mut y = x;
        let mut f = vec![false; 10];
        let mut ok = true;
        while y > 0 {
            if f[y % 10] {
                ok = false;
                break;
            }
            f[y % 10] = true;
            y /= 10;
        }
        if ok {
            println!("{}", x);
            return;
        }
    }

    println!("-1");
}

//spnauti-rusT
use std::io::*;
use std::str::{self,*};
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_macros)]
macro_rules! m {
    ($c:tt, $x:expr, $y:expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
#[allow(unused_macros)]
macro_rules! l {
    ($($v:ident),* = $i:ident.$f:ident $a:tt) => {
        $( let $v = $i.$f$a; )*
    };
    ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {
        $( let $v:$t = $i.$f$a; )*
    };
}
struct WordReader<'a> { it : SplitAsciiWhitespace<'a> }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).ok();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn f(&mut self) ->    f64 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn sk(&mut self, n: usize) { self.it.nth(n - 1); }
    fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> {
        self.ip(n).into_iter()
    }
    fn vi(&mut self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
        self.vp(n).into_iter()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}
//------------------- End rusT

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    l!(a,b = input.u());
    for i in a..=b {
        let mut x = i;
        let mut c = [0; 10];
        while x > 0 {
            c[x % 10] += 1;
            x /= 10;
        }
        if c.iter().max().unwrap() == &1 {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}

use std::io::{self, BufRead, Write};
use std::str::{self, FromStr, SplitAsciiWhitespace};

fn main() {
    let stdin = io::stdin();
    solve(stdin.lock(), io::stdout());
}

type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

struct Scanner<'a, R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'a>,
}

impl<R: BufRead> Scanner<'_, R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: Vec::new(),
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    fn try_token<T>(&mut self) -> Result<T>
        where T: FromStr,
              <T as FromStr>::Err: 'static + std::error::Error
    {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return Ok(token.parse()?);
            }
            self.buf_str.clear();
            let bytes_read = self.reader
                .read_until(b'\n', &mut self.buf_str)?;
            if bytes_read == 0 {
                return Err(Box::new(io::Error::from(io::ErrorKind::UnexpectedEof)));
            }
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                ::std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    fn token<T>(&mut self) -> T
        where T: FromStr,
              <T as FromStr>::Err: 'static + std::error::Error
    {
        self.try_token().unwrap()
    }
}

fn solve<R: BufRead, W: Write>(input: R, mut output: W) {
    let mut scan = Scanner::new(input);

    let l: u32 = scan.token();
    let r: u32 = scan.token();
    let mut met;
    'numbers: for x in l..=r {
        met = [false; 10];
        let mut xx = x;
        while xx != 0 {
            let digit = (xx % 10) as usize;
            if met[digit] { continue 'numbers; }
            met[digit] = true;
            xx /= 10;
        }
        writeln!(output, "{}", x).unwrap();
        return;
    }
    writeln!(output, "-1").unwrap();
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn example1() {
        let inp = &b"121 130\n"[..];
        let mut out = String::new();
        solve(inp, unsafe { out.as_mut_vec() });
        assert_eq!(out, "123\n");
    }

    #[test]
    fn example2() {
        let inp = &b"98766 100000\n"[..];
        let mut out = String::new();
        solve(inp, unsafe { out.as_mut_vec() });
        assert_eq!(out, "-1\n");
    }

    #[test]
    fn badhead() {
        let inp = &b"110 119\n"[..];
        let mut out = String::new();
        solve(inp, unsafe { out.as_mut_vec() });
        assert_eq!(out, "-1\n");
    }

    #[test]
    fn t() {
        let inp = &b"1211 1240\n"[..];
        let mut out = String::new();
        solve(inp, unsafe { out.as_mut_vec() });
        assert_eq!(out, "1230\n");
    }
}

//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        l: usize,
        r: usize,
    }
    for x in l..=r {
        let s: Vec<char> = x.to_string().chars().collect();
        let k = s.len();
        let mut ok = true;
        for i in 0..k {
            for j in 0..i {
                if s[i] == s[j] {
                    ok = false;
                }
            }
        }
        if ok {
            println!("{}", x);
            return;
        }
    }
    println!("-1");
}

fn main() {
    run();
}

use std::io;

use std::collections::HashSet;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let input: Vec<u32> = buf.trim().split(' ').map(|x| x.parse().unwrap()).collect();
    let (left, right) = (input[0], input[1]);
    let res = (left..=right)
        .map(|x| {
            let s = x.to_string();
            (
                x.to_string(),
                s.chars().collect::<HashSet<_>>().len(),
                s.chars().count(),
            )
        })
        .find(|(_, len1, len2)| len1 == len2);
    let res = match res {
        Some(r) => r.0,
        None => (-1).to_string(),
    };
    println!("{}", res);
}

struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).expect("Fail to read");
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn is_good(x: usize) -> bool {
    let mut isused: [bool; 10] = [false; 10];
    let mut a = x;
    while a > 0 {
        let dig = a % 10;
        a /= 10;
        if isused[dig] {
            return false;
        }
        isused[dig] = true;
    }
    return true;
}

fn _main() {
    let mut scan = Scan::new();
    let l: usize = scan.next();
    let r: usize = scan.next();
    for i in l..=r {
        if is_good(i) {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}

fn ud(mut a: i32) -> bool {
    let mut m = 0;
    while a != 0 {
        let c = 1 << (a % 10);
        if m & c != 0 {
            return false;
        }
        m |= c;
        a /= 10;
    }
    true
}

fn solve(a: i32, b: i32) -> i32 {
    for i in a..=b {
        if ud(i) {
            return i;
        }
    }
    -1
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut it = buf.trim().split_whitespace();
    println!(
        "{}",
        solve(
            it.next().unwrap().parse().unwrap(),
            it.next().unwrap().parse().unwrap()
        )
    );
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_canonical() {
        assert_eq!(solve(121, 130), 123);
        assert_eq!(solve(98766, 100000), -1);
    }
}

use std::io;
use std::collections::HashSet;

// type Matrix = Vec<Vec<char>>;

fn read_line() -> String {
    let mut input_line = String::new();
    io::stdin().read_line(&mut input_line).unwrap();
    return String::from(input_line.trim());
}

fn read_line_vec() -> Vec<i64> {
    return read_line().split(' ')
        .map(|s| s.parse().unwrap())
        .collect();
}

fn read_line_pair() -> (i64, i64) {
    let vec = read_line_vec();
    return (vec[0], vec[1]);
}

fn is_diff(n: i64) -> bool {
    let mut nn = n;
    let mut hs = HashSet::new();
    while nn > 0 {
        let ni = nn % 10;
        nn /= 10;
        if hs.contains(&ni) {
            return false;
        }
        hs.insert(ni);
    }
    return true;
}

fn has(l: i64, r: i64) -> Option<i64> {
    for i in l..(r+1) {
        if is_diff(i) {
            return Some(i);
        }
    }
    return None;
}

fn main() {
    let (l, r) = read_line_pair();

    // let r = is_diff(1101231);

    match has(l, r) {
        Some(n) => println!("{}", n),
        None => println!("-1")
    }

    // println!("{:?}", r);

}

#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

fn ok(a: usize) -> bool {
    let mut a = a;
    let mut d = vec![];
    while a > 0 {
        d.push(a % 10);
        a /= 10;
    }
    use std::collections::HashSet;
    let s : HashSet<_> = d.iter().collect();
    d.len() == s.len()
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    for a in n..m+1 {
        if ok(a) {
            put!(a);
            return;
        }
    }
    put!(-1);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::HashSet;

type GenError = Box<dyn std::error::Error>;
type GenResult<T> = Result<T, GenError>;

struct Reader {}

impl Reader {
    #[allow(unused)]
    fn read_string() -> GenResult<String> {
        let mut string: String = String::new();
        std::io::stdin().read_line(&mut string)?;
        Ok(string.trim().to_string())
    }

    #[allow(unused)]
    fn read_tokens() -> GenResult<Vec::<String>> {
        let mut string: String = String::new();
        std::io::stdin().read_line(&mut string)?;
        let mut v = Vec::new();
        for value in string.split_whitespace() {
            v.push(value.to_string());
        }
        Ok(v)
    }
}

fn main() {
    let tokens = Reader::read_tokens().unwrap();
    let n: i32 = tokens[0].parse().unwrap();
    let m: i32 = tokens[1].parse().unwrap();
    for value in n .. m + 1 {
        let mut chars = HashSet::new();
        let string = value.to_string();
        for ch in string.chars(){
            chars.insert(ch);
        }
        if chars.len() == string.len() {
            println!("{}", string);
            return;
        }
    }
    println!("{}", -1);
}

use std::io;
use std::collections::HashSet;

// type Matrix = Vec<Vec<char>>;

fn read_line() -> String {
    let mut input_line = String::new();
    io::stdin().read_line(&mut input_line).unwrap();
    return String::from(input_line.trim());
}

fn read_line_vec() -> Vec<i64> {
    return read_line().split(' ')
        .map(|s| s.parse().unwrap())
        .collect();
}

fn read_line_pair() -> (i64, i64) {
    let vec = read_line_vec();
    return (vec[0], vec[1]);
}

fn is_diff(n: i64) -> bool {
    let mut nn = n;
    let mut hs = HashSet::new();
    while nn > 0 {
        let ni = nn % 10;
        nn /= 10;
        if hs.contains(&ni) {
            return false;
        }
        hs.insert(ni);
    }
    return true;
}

fn has(l: i64, r: i64) -> Option<i64> {
    for i in l..r {
        if is_diff(i) {
            return Some(i);
        }
    }
    return None;
}

fn main() {
    let (l, r) = read_line_pair();

    // let r = is_diff(1101231);

    match has(l, r) {
        Some(n) => println!("{}", n),
        None => println!("-1")
    }

    // println!("{:?}", r);

}