#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
inline T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return a * (b / gcd(a, b));
}
vector<int> run, ans;
int main() {
  for (int i = (int)0; i < (int)26; ++i) run.push_back(0);
  string s, t, res = "";
  char more, temp;
  cin >> s >> t;
  int n = int((t).size()), m = int((s).size()), pos = -1, last = -1;
  for (int i = (int)0; i < (int)m; ++i) run[s[i] - 'a']++;
  for (int i = (int)0; i < (int)n; ++i) {
    bool ok = false;
    for (char ch = t[i] + 1; ch <= 'z'; ch++) {
      if (run[ch - 'a']) {
        ok = true;
        temp = ch;
        break;
      }
    }
    if (ok) {
      pos = i;
      more = temp;
      ans = run;
      ans[more - 'a']--;
    }
    if (run[t[i] - 'a']) {
      run[t[i] - 'a']--;
      last = i;
    } else
      break;
  }
  string res1 = "";
  bool ok = false;
  if (pos == -1 && last < n - 1)
    printf("%d\n", pos);
  else if (last == n - 1) {
    res1 = t;
    for (int i = (int)0; i < (int)26; ++i) {
      for (int j = (int)0; j < (int)run[i]; ++j) res1 += (char)(i + 'a');
    }
    if (res1 == t && pos == -1) {
      printf("%d\n", -1);
      return 0;
    }
    if (res1 != t) ok = true;
  }
  if (pos >= 0) {
    res += t.substr(0, pos);
    res += more;
    for (int i = (int)0; i < (int)26; ++i) {
      for (int j = (int)0; j < (int)ans[i]; ++j) res += (char)(i + 'a');
    }
  }
  if (ok)
    cout << res1 << endl;
  else
    cout << res << endl;
  return 0;
}
