#include <bits/stdc++.h>
using namespace std;
string str, str2;
int check(int i, int n, int m, int ara[]) {
  int l = 26;
  int ara2[30];
  for (int i = 1; i <= 26; i++) ara2[i] = ara[i];
  for (int j = i; j < max(n, m) && l; j++) {
    if (str2[j] == '\0') return 1;
    if (str[j] == '\0') return 0;
    while (ara2[l] == 0 && l) l--;
    int k = str2[j] - 96;
    if (l == 0 || l < (k)) return 0;
    if (l > (k)) return 1;
    ara2[l]--;
  }
  return 0;
}
void make(int st, int n, int ara[]) {
  int l = 1;
  for (int i = st; i < n && l < 27; i++) {
    while (ara[l] == 0 && l < 27) l++;
    ara[l]--;
    str[i] = l + 96;
  }
  str[n] = '\0';
  cout << str << endl;
}
int ara[40];
int main() {
  cin >> str >> str2;
  int l, n, m, k;
  n = str.size();
  m = str2.size();
  for (int i = 0; str[i]; i++) {
    ara[str[i] - 96]++;
  }
  for (int i = 0; str2[i]; i++) {
    k = str2[i] - 96;
    if (ara[k]) {
      ara[k]--;
      l = check(i + 1, n, m, ara);
      if (l) {
        str[i] = str2[i];
        continue;
      }
      ara[k]++;
      int p = k + 1;
      while (0 == ara[p] && p < 27) p++;
      if (p == 27) {
        printf("-1\n");
        return 0;
      }
      str[i] = p + 96;
      ara[p]--;
      make(i + 1, n, ara);
      return 0;
    }
    int p = k + 1;
    while (0 == ara[p] && p < 27) p++;
    if (p == 27) {
      printf("-1\n");
      return 0;
    }
    str[i] = p + 96;
    ara[p]--;
    make(i + 1, n, ara);
    return 0;
  }
  make(m, n, ara);
}
