Under construction

Still being built. Things may change

Distinct Digits

Time limit1sMemory limit1024 MB

Summary
Given l and r up to 10^5, the task finds any number in the range whose digits are all different, or reports -1.
Level

Easy2 of 10

Topics
Brute force, Math
Solved
No attempts yet

Problem

You are given two integers ll and rr. Find an integer xx that satisfies the following conditions.

  • l≤x≤rl \le x \le r.
  • All digits of xx are different.

If there are multiple answers, print any of them.

Input

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

Output

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

Notes

In the first example, 123123 is one possible answer. The number 121121 is not valid, because the digit 11 appears more than once.

In the second example, there is no valid answer.

Examples2

  1. Example 1

    Input
    121 130
    
    Expected output
    123
    
  2. Example 2

    Input
    98766 100000
    
    Expected output
    -1