#include <bits/stdc++.h>
int main(void) {
  using namespace std;
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int p, q;
  cin >> p >> q;
  for (; p <= q; ++p) {
    set<char> S;
    string s = to_string(p);
    int r = 1;
    for (auto a : s) {
      if (S.find(a) != S.end()) r = 0;
      S.insert(a);
    }
    if (r == 1) {
      cout << p << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
