#include <bits/stdc++.h>
using namespace std;
int maxDigitInNumber(int n) {
  n = abs(n);
  int numOfDigits = (int)log10(n) + 1;
  int digits[100];
  int helper[100] = {0};
  int counter = 0;
  int maxSize = 0;
  int number = 0;
  for (int i = 0; i <= numOfDigits; i++) {
    digits[i] = n % 10;
    n /= 10;
  }
  for (int i = 0; i < numOfDigits; i++) {
    if (helper[i] == 0) {
      counter = 0;
      for (int j = i; j < numOfDigits; j++) {
        if (digits[j] == digits[i]) {
          counter++;
          helper[j] = 1;
        }
        if (counter > maxSize) {
          maxSize = counter;
          number = digits[i];
        }
      }
    }
  }
  return maxSize;
}
int main() {
  int l, r, p = 0;
  cin >> l >> r;
  for (int i = l; i <= r; i++) {
    if (maxDigitInNumber(i) == 1) {
      cout << i;
      p++;
      break;
    }
  }
  if (p == 0) cout << "-1";
  return 0;
}
