#include <bits/stdc++.h>
using namespace std;
long long ex(long long a, long long b) {
  long long tmp = 1;
  for (int i = 0; i < b; i++) {
    tmp = tmp * a;
  }
  return tmp;
}
int main() {
  long long r, l, tmp, ans = -1;
  bool good = 1;
  cin >> l >> r;
  for (long long i = l; i <= r; i++) {
    for (long long k = 0; k <= 5; k++) {
      for (long long j = 0; j <= 5; j++) {
        if (i / (ex(10, j)) % 10 == (i / (ex(10, k))) % 10 && ex(10, k) <= i &&
            ex(10, j) <= i && j != k) {
          good = 0;
        }
      }
    }
    if (good) {
      ans = i;
    }
    good = 1;
  }
  cout << ans << endl;
}
