#include <bits/stdc++.h>
using namespace std;
const int M = 5000 + 10;
const double eps = 1e-9;
int sprefix[M][30];
int tprefix[M][30];
int ihashs[30];
int ihasht[30];
int sval[M];
int tval[M];
int main() {
  string s, t;
  cin >> s >> t;
  int slen = s.length();
  int tlen = t.length();
  for (int i = 0; i < slen; i++) {
    sval[i] = s[i] - 'a' + 1;
    ihashs[sval[i]]++;
  }
  for (int i = 0; i < tlen; i++) {
    tval[i] = t[i] - 'a' + 1;
    ihasht[tval[i]]++;
  }
  sprefix[0][sval[0]]++;
  tprefix[0][tval[0]]++;
  for (int i = 1; i < slen; i++) {
    for (int j = 1; j <= 26; j++) {
      sprefix[i][j] = sprefix[i - 1][j] + (sval[i] == j);
    }
  }
  for (int i = 1; i < tlen; i++) {
    for (int j = 1; j <= 26; j++) {
      tprefix[i][j] = tprefix[i - 1][j] + (tval[i] == j);
    }
  }
  int vlen = slen;
  int keyid = -1;
  for (int i = vlen - 1; i >= 0; i--) {
    bool ok1 = true;
    if (i - 1 >= 0) {
      for (int j = 1; j <= 26; j++) {
        if (ihashs[j] < tprefix[min(i - 1, tlen - 1)][j]) {
          ok1 = false;
        }
      }
    }
    bool ok2 = false;
    int tc = tval[i];
    for (int j = tc + 1; j <= 26; j++) {
      if (ihashs[j] >= tprefix[i][j] + 1) {
        ok2 = true;
      }
    }
    if (ok1 && ok2) {
      keyid = i;
      break;
    }
  }
  if (keyid == -1) {
    cout << "-1" << endl;
  } else {
    for (int i = 0; i < min(keyid, tlen); i++) {
      for (int j = tval[i]; j <= 26; j++) {
        if (ihashs[j] > 0) {
          char c = 'a' + j - 1;
          cout << c;
          ihashs[j]--;
          break;
        }
      }
    }
    if (tlen - 1 < keyid) {
      for (int j = 1; j <= 26; j++) {
        while (ihashs[j] > 0) {
          char c = 'a' + j - 1;
          cout << c;
          ihashs[j]--;
        }
      }
    } else {
      int tc = tval[keyid] + 1;
      for (int i = tc; i <= 26; i++) {
        if (ihashs[i] > 0) {
          char c = 'a' + i - 1;
          cout << c;
          ihashs[i]--;
          break;
        }
      }
      for (int i = 1; i <= 26; i++) {
        while (ihashs[i] > 0) {
          char c = 'a' + i - 1;
          cout << c;
          ihashs[i]--;
        }
      }
    }
  }
  return 0;
}
