#include <bits/stdc++.h>
using namespace std;
string s, t, ans;
int len, len1;
int counts[5111] = {0};
int func(int index, int state) {
  if (index == len)
    return state;
  else {
    for (int i = (int)'a'; i <= (int)'z'; ++i)
      if (counts[i] and (state or index >= len1 or i >= t[index])) {
        ans[index] = (char)i;
        counts[i]--;
        if (func(index + 1, (state or index >= len1 or i > t[index]))) return 1;
        counts[i]++;
      }
  }
  return 0;
}
int main() {
  cin >> s >> t;
  ans = s;
  len = s.size();
  len1 = t.size();
  for (int i = 0; i < len; ++i) counts[s[i]]++;
  if (func(0, 0) == 1)
    cout << ans << "\n";
  else
    cout << "-1"
         << "\n";
}
