#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
int n, m, num[30], num2[30];
char s[N], t[N];
bool chk(int x) {
  for (int i = 1; i <= x; i++) num[t[i] - 'a']--;
  for (int i = 0; i <= 25; i++)
    if (num[i] < 0) return 0;
  return 1;
}
int main() {
  scanf("%s%s", s + 1, t + 1);
  n = strlen(s + 1), m = strlen(t + 1);
  for (int i = 1; i <= n; i++) num[s[i] - 'a']++;
  for (int i = 0; i <= 25; i++) num2[i] = num[i];
  if (n > m) {
    if (chk(m)) {
      for (int j = 1; j <= m; j++) printf("%c", t[j]);
      int pos = 0;
      for (int j = m + 1; j <= n; j++) {
        while (pos <= 25 && !num[pos]) ++pos;
        printf("%c", pos + 'a');
        --num[pos];
      }
      puts("");
      return 0;
    }
    for (int i = m - 1; i >= 0; i--) {
      for (int j = 0; j <= 25; j++) num[j] = num2[j];
      if (chk(i)) {
        int ff = -1;
        for (int j = t[i + 1] - 'a' + 1; j <= 25; j++) {
          if (num[j]) {
            ff = j;
            break;
          }
        }
        if (ff == -1) continue;
        for (int j = 1; j <= i; j++) printf("%c", t[j]);
        printf("%c", ff + 'a');
        --num[ff];
        int pos = 0;
        for (int j = i + 2; j <= n; j++) {
          while (pos <= 25 && !num[pos]) ++pos;
          printf("%c", pos + 'a');
          --num[pos];
        }
        puts("");
        return 0;
      }
    }
  } else {
    for (int i = n - 1; i >= 0; i--) {
      for (int j = 0; j <= 25; j++) num[j] = num2[j];
      if (chk(i)) {
        int ff = -1;
        for (int j = t[i + 1] - 'a' + 1; j <= 25; j++) {
          if (num[j]) {
            ff = j;
            break;
          }
        }
        if (ff > -1) {
          for (int j = 1; j <= i; j++) printf("%c", t[j]);
          printf("%c", ff + 'a');
          --num[ff];
          int pos = 0;
          for (int j = i + 2; j <= n; j++) {
            while (pos <= 25 && !num[pos]) ++pos;
            printf("%c", pos + 'a');
            --num[pos];
          }
          puts("");
          return 0;
        }
      }
    }
  }
  puts("-1");
  return 0;
}
