#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int l, r, n, r2, flag = 0, q, n2, arr[50], g, n3;
  cin >> l >> r;
  n = l + ((r - l + 1) / 2);
  n2 = n;
  n3 = n;
  for (int i = n3; i <= r; i++) {
    flag = 0;
    q = 0;
    r2 = 0;
    g = 0;
    while (n2 > 0) {
      q = n2 / 10;
      r2 = n2 % 10;
      n2 = n2 / 10;
      arr[g] = r2;
      g++;
    }
    for (int y = 0; y < g; y++) {
      for (int u = y + 1; u < g; u++) {
        if (arr[y] == arr[u]) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 1) {
      n = n + 1;
      n2 = n;
    } else if (flag == 0) {
      break;
    }
  }
  if (flag == 0) {
    cout << n;
  } else if (flag == 1) {
    cout << -1;
  }
  return 0;
}
