#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
void solution() {
  long long l, r;
  cin >> l >> r;
  vector<int> n;
  n.resize(10);
  bool ok;
  for (int i = l; i <= r; ++i) {
    int ic = i;
    while (ic) {
      n[ic % 10] += 1;
      ic /= 10;
    }
    ok = std::all_of(n.begin(), n.end(), [](int i) { return i <= 1; });
    if (ok) {
      cout << i;
      break;
    }
    std::fill(n.begin(), n.end(), 0);
  }
  if (!ok) {
    cout << "-1";
  }
}
int main() {
  solution();
  return 0;
}
