#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e9 + 7;
long long n, k, f[30];
string s, t, r;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, a, b, ans = 0;
  cin >> s >> t;
  r = s;
  sort(r.begin(), r.end(), greater<long long>());
  if (r <= t) return cout << -1, 0;
  n = s.size();
  for (i = 0; i < n; i++) f[s[i] - 'a']++;
  k = t.size();
  for (i = 0; i < min(k, n); i++) {
    if (f[t[i] - 'a']) {
      s[i] = t[i], f[t[i] - 'a']--;
    } else {
      for (j = t[i] - 'a'; j < 26; j++)
        if (f[j]) {
          s[i] = char(j + 'a');
          f[j]--;
          i++;
          for (j = 0; j < 26; j++) {
            while (f[j]--) s[i] = char(j + 'a'), i++;
          }
          cout << s;
          return 0;
        }
      for (j = 25; j >= 0; j--) {
        while (f[j]--) s[i] = char(j + 'a'), i++;
      }
      next_permutation(s.begin(), s.end());
      cout << s;
      return 0;
    }
  }
  if (i == n) next_permutation(s.begin(), s.end());
  for (j = 0; j < 26; j++) {
    while (f[j]--) s[i] = char(j + 'a'), i++;
  }
  cout << s;
}
