#include <bits/stdc++.h>
using namespace std;
int f[10];
bool IsGay(int x) {
  int i, c;
  for (i = 0; i <= 9; i++) {
    f[i] = 0;
  }
  do {
    c = x % 10;
    if (f[c] == 1)
      return 0;
    else
      f[c]++;
    x /= 10;
  } while (x);
  return 1;
}
int main() {
  int l, r, n;
  scanf("%d%d", &l, &r);
  for (; l <= r; l++) {
    if (IsGay(l)) break;
    if (l == r) {
      l = -1;
      break;
    }
  }
  printf("%d", l);
  return 0;
}
