#include <bits/stdc++.h>
const int N = 5005;
char a[N], b[N], ans[N];
int s[30];
int main() {
  scanf("%s%s", a, b);
  if (strcmp(a, b) == 0) {
  }
  int n = strlen(a);
  for (int i = 0; i < n; i++) {
    s[a[i] - 'a']++;
  }
  n = strlen(b);
  int pos = 0;
  bool f = 0;
  for (int i = 0; i < n; i++) {
    int t = b[i] - 'a';
    if (s[t] > 0) {
      s[t]--;
      ans[pos++] = b[i];
    } else {
      for (int j = t + 1; j < 26; j++) {
        if (s[j] > 0) {
          s[j]--;
          ans[pos++] = 'a' + j;
          f = 1;
          break;
        }
      }
      if (!f) {
        for (int j = pos - 1; j >= 0; j--) {
          t = ans[j] - 'a';
          s[t]++;
          for (int k = t + 1; k < 26; k++) {
            if (s[k] > 0) {
              s[k]--;
              ans[j] = 'a' + k;
              f = 1;
              pos = j + 1;
              break;
            }
          }
          if (f) break;
        }
      }
      break;
    }
  }
  ans[pos] = '\0';
  if (strcmp(ans, b) == 0 && strlen(a) <= strlen(b)) {
    for (int j = pos - 1; j >= 0; j--) {
      int t = ans[j] - 'a';
      s[t]++;
      for (int k = t + 1; k < 26; k++) {
        if (s[k] > 0) {
          s[k]--;
          ans[j] = 'a' + k;
          f = 1;
          pos = j + 1;
          break;
        }
      }
      if (f) break;
    }
  }
  if (strcmp(ans, b) == 0 && strlen(a) > strlen(b)) f = 1;
  if (f) {
    for (int j = 0; j < 26; j++) {
      while (s[j]) {
        ans[pos++] = 'a' + j;
        s[j]--;
      }
    }
    ans[pos] = '\0';
    printf("%s\n", ans);
  } else {
    puts("-1");
  }
  return 0;
}
