#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  map<char, int> ss;
  for (int i = 0; i < s.length(); ++i) {
    ++ss[s[i]];
  }
  string r = "|";
  string pre = "";
  for (int i = 0; i <= t.length(); ++i) {
    if (i == t.length()) {
      string rr = pre;
      for (map<char, int>::iterator j = ss.begin(); j != ss.end(); ++j) {
        rr += string(j->second, j->first);
      }
      if (rr > t) r = min(r, rr);
    } else {
      map<char, int>::iterator it = ss.upper_bound(t[i]);
      if (it != ss.end()) {
        string rr = pre + it->first;
        for (map<char, int>::iterator j = ss.begin(); j != ss.end(); ++j) {
          rr += string(j->second - (j->first == it->first ? 1 : 0), j->first);
        }
        r = min(r, rr);
      }
      if (!ss.count(t[i])) break;
      if (--ss[t[i]] == 0) {
        ss.erase(t[i]);
      }
      pre += t[i];
    }
  }
  if (r == "|") {
    cout << -1 << endl;
  } else {
    cout << r << endl;
  }
}
