#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int N = 200000 + 5;
void work() {
  int l, r;
  scanf("%d%d", &l, &r);
  int ok = 1, ans = -1;
  for (int i = l; i <= r; i++) {
    int t = i;
    int a[10], l = 0;
    memset(a, 0, sizeof(a));
    while (t) {
      a[l++] = t % 10;
      t /= 10;
    }
    ok = 1;
    for (int i = 0; i < (l); i++) {
      for (int j = i + 1; j < l; j++) {
        if (a[i] == a[j]) {
          ok = 0;
          break;
        }
      }
      if (!ok) break;
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  printf("%d\n", ans);
}
int main() {
  work();
  return 0;
}
