#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 8;
int a[maxn];
int n, m;
bool check(int x) {
  int vis[15] = {0};
  while (x) {
    if (vis[x % 10] != 0)
      return false;
    else
      vis[x % 10] = 1;
    x /= 10;
  }
  return true;
}
int main() {
  while (cin >> n >> m) {
    int ok = 0;
    for (int i = n; i <= m; i++) {
      if (check(i)) {
        ok = 1;
        cout << i << endl;
        break;
      }
    }
    if (!ok) cout << -1 << endl;
  }
}
