#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int t, l, r;
int cnt[10];
bool ok(int x) {
  fill(cnt, cnt + 10, 0);
  while (x > 0) {
    ++cnt[x % 10];
    x /= 10;
  }
  for (int i = 0; i < 10; ++i) {
    if (cnt[i] > 1) {
      return false;
    }
  }
  return true;
}
int main() {
  t = 1;
  while (t--) {
    cin >> l >> r;
    while (l <= r && !ok(l)) {
      ++l;
    }
    if (l > r) {
      cout << -1 << endl;
      continue;
    }
    cout << l << endl;
  }
  return 0;
}
