#include <bits/stdc++.h>
using namespace std;
int l, r;
string s;
bool b_occured[10];
bool judge() {
  memset(b_occured, 0, sizeof(b_occured));
  bool ret = false;
  for (int i = 0; i < s.length(); i++) {
    if (b_occured[s[i] - '0'] == false)
      b_occured[s[i] - '0'] = true;
    else {
      ret = true;
    }
  }
  return ret;
}
int main() {
  cin >> l >> r;
  s = to_string(l);
  while (judge()) {
    l++;
    s = to_string(l);
  }
  if (l <= r)
    cout << l << '\n';
  else
    cout << "-1\n";
  return 0;
}
