#include <bits/stdc++.h>
using namespace std;
void base() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  base();
  int l, r, n;
  bool flag = true;
  cin >> l >> r;
  while (l <= r) {
    int n = l;
    flag = true;
    int arr[11] = {0};
    while (n) {
      if (arr[n % 10]) {
        flag = false;
        break;
      }
      arr[n % 10] = 1;
      n /= 10;
    }
    if (flag) break;
    l++;
  }
  if (flag) {
    cout << l << "\n";
  } else {
    cout << "-1\n";
  }
  return 0;
}
