#include <bits/stdc++.h>
using namespace std;
string s, t;
char ans[5005];
int freq[27];
int func(int index, int possible) {
  if (index == s.length()) return possible;
  for (int i = 0; i < 26; i++) {
    if (freq[i] > 0 && (possible || i >= t[index] - 'a')) {
      ans[index] = i + 'a';
      freq[i]--;
      if (func(index + 1, possible || (i > t[index] - 'a'))) return 1;
      freq[i]++;
    }
  }
  return 0;
}
int main() {
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++) freq[s[i] - 'a']++;
  if (func(0, 0) == 0)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
