#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = n; i <= m; i++) {
    set<int> s;
    int x = i;
    int len = log10(x) + 1;
    while (x) {
      s.insert(x % 10);
      x /= 10;
    }
    if (s.size() == len) return cout << i, 0;
  }
  cout << -1;
}
