#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, i, x, count, ans = -1;
  cin >> n >> m;
  for (i = n; i <= m; i++) {
    x = i;
    count = 0;
    set<int> st;
    while (x > 0) {
      st.insert(x % 10);
      x = x / 10;
      count++;
    }
    x = st.size();
    if (count == x) {
      ans = i;
      break;
    }
  }
  cout << ans;
}
