#include <bits/stdc++.h>
using namespace std;
int mark[130], ans[5005];
string s1, s2;
bool making(int p, int ck) {
  if (p == s1.length()) return ck;
  for (int i = 'a'; i <= 'z'; i++) {
    if (mark[i] && (i >= s2[p] || ck)) {
      ans[p] = i;
      mark[i]--;
      if (making(p + 1, ck || i > s2[p])) return true;
      mark[i]++;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s1 >> s2;
  for (int i = 0; i < s1.length(); i++) mark[s1[i]]++;
  if (!making(0, 0))
    cout << -1 << endl;
  else {
    for (int i = 0; i < s1.length(); i++) cout << (char)ans[i];
    cout << endl;
  }
  return 0;
}
