#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
long long t;
long long mod = 1e9 + 7;
long long BigMod(long long base, long long pow, long long mod) {
  if (pow == 0 || base == 1)
    return 1;
  else if (pow == 1)
    return base;
  else if (pow % 2)
    return BigMod(base, pow - 1, mod) * base % mod;
  else {
    long long x = (BigMod(base, pow / 2, mod) % mod);
    x = (x * x) % mod;
    return x;
  }
}
string s, p;
int main() {
  long long a, b, c, d, e, f, g, i, j;
  long long n, m, k;
  cin >> s >> p;
  long long arr[27] = {0};
  n = s.size();
  m = p.size();
  for (i = 0; i < n; i++) {
    arr[s[i] - 'a']++;
  }
  f = -1;
  vector<long long> ans;
  for (i = 0; i < n; i++) {
    if (i >= m || f == 0)
      d = 0, f = 0;
    else
      d = p[i] - 'a';
    for (j = d; j < 26; j++) {
      if (arr[j]) {
        ans.push_back(j);
        arr[j]--;
        if (j != d) f = 0;
        break;
      }
    }
    if (j == 26 || (i == n - 1 && f == -1)) {
      if (j == 26) i = i - 1;
      for (; i >= 0; i--) {
        a = ans.back();
        arr[a]++;
        ans.pop_back();
        d = p[i] - 'a';
        for (j = d + 1; j < 26; j++) {
          if (arr[j]) {
            ans.push_back(j);
            arr[j]--;
            f = 0;
            break;
          }
        }
        if (j != 26) break;
      }
      if (i == -1) break;
    }
  }
  if (i == n && f == 0) {
    for (i = 0; i < n; i++) {
      char cc = ans[i] + 'a';
      cout << cc;
    }
    cout << endl;
  } else
    cout << "-1" << endl;
  return 0;
}
