#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long long LINF = 1000000000000000000LL;
const double eps = 1e-9;
void prepare() {}
const int nmax = 5005;
char s[nmax];
char t[nmax];
int cnt[30];
int cur[30];
int n, m, ans = -1;
string bst, tmp;
bool solve() {
  scanf("%s%s", s, t);
  n = strlen(s);
  m = strlen(t);
  for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;
  bst = "";
  for (int pref = 0; pref <= min(n, m); pref++) {
    tmp = "";
    for (int i = 0; i < 30; i++) cur[i] = cnt[i];
    bool ok = true;
    for (int i = 0; i < pref; i++) {
      cur[t[i] - 'a']--;
      if (cur[t[i] - 'a'] < 0) ok = false;
      tmp.push_back(t[i]);
    }
    if (!ok) continue;
    int id = -1;
    int bound = (pref < m ? t[pref] - 'a' : -1);
    for (int i = bound + 1; i < 30; i++) {
      if (cur[i] > 0) {
        id = i;
        break;
      }
    }
    if (id == -1) continue;
    cur[id]--;
    tmp.push_back('a' + id);
    for (int i = 0; i < 30; i++) {
      for (int it = 0; it < cur[i]; it++) {
        tmp.push_back('a' + i);
      }
    }
    if (bst == "" || bst > tmp) bst = tmp;
  }
  if (bst == "")
    printf("-1\n");
  else
    printf("%s\n", bst.c_str());
  return false;
}
int main() {
  prepare();
  while (solve())
    ;
  return 0;
}
