#include <bits/stdc++.h>
int main() {
  int a, b;
  while (~scanf("%d%d", &a, &b)) {
    int q;
    int kk;
    int j, num, mm = 0;
    int n;
    for (n = a; n <= b; n++) {
      j = 1;
      kk = n;
      num = 1;
      for (q = 0; n / 10 != 0; q++) {
        if (n / 10 != 0) {
          num++;
          n /= 10;
        }
      }
      n = kk;
      int a[6];
      for (q = 0; q <= 10; q++) {
        a[q] = n % 10;
        n /= 10;
        if (n < 10) {
          a[q + 1] = n;
          break;
        }
      }
      n = kk;
      int p, l;
      for (p = 0; p < num - 1; p++) {
        for (l = p + 1; l < num; l++) {
          if (a[p] == a[l]) {
            j = 0;
            break;
          }
        }
        if (j == 0) break;
        j = 1;
      }
      if (j == 1) break;
    }
    if (j == 1) printf("%d\n", kk);
    if (j == 0) printf("-1\n");
  }
}
