#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int a1[28];
string repeat(char ch, int n) {
  string s = "";
  s += ch;
  string ans = "";
  while (n) {
    if (n & 1) ans += s;
    s += s;
    n >>= 1;
  }
  return ans;
}
string dfs(int x) {
  if (x == s2.size()) {
    if (s1.size() == s2.size()) return "-1";
    string temstring = "";
    for (int i = 0; i < 26; i++) temstring += repeat(i + 'a', a1[i]);
    return temstring;
  }
  int p = s2[x] - 'a';
  if (a1[p] != 0) {
    a1[p]--;
    string temstring = dfs(x + 1);
    if (temstring != "-1") {
      return s2[x] + temstring;
    } else {
      a1[p]++;
    }
  }
  for (int i = p + 1; i < 26; i++) {
    if (a1[i] > 0) {
      string temstring = "";
      temstring += (i + 'a');
      a1[i]--;
      for (int j = 0; j < 26; j++) temstring += repeat(j + 'a', a1[j]);
      return temstring;
    }
  }
  return "-1";
}
int main() {
  cin >> s1 >> s2;
  for (int i = s1.size() - 1; i >= 0; i--) a1[s1[i] - 'a']++;
  cout << dfs(0) << endl;
  return 0;
}
