#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lb = 1000;
void vrikodara(long long n = 12) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(n) << fixed;
}
void solve() {
  string s, t;
  cin >> s >> t;
  vector<long long> v1(26, 0), v2(26, 0);
  for (auto i : s) v1[i - 'a']++;
  for (auto i : t) v2[i - 'a']++;
  long long n = t.length();
  long long a = n;
  if (s.length() <= n) {
    a = s.length();
    a--;
  }
  t += 55;
  for (long long i = a - 1; i >= -1; i--) {
    vector<long long> v = v1;
    bool flag = true;
    string ans = "";
    for (long long j = 0; j <= i; j++) {
      if (!v[t[j] - 'a']) {
        flag = false;
        break;
      }
      ans += t[j];
      v[t[j] - 'a']--;
    }
    if (flag) {
      char ch = t[i + 1];
      flag = false;
      for (long long i = 0; i < 26; i++) {
        if (v[i] && (char)('a' + i) > ch) {
          v[i]--;
          char r = (char)(i + 'a');
          ans += r;
          for (long long i = 0; i < 26; i++) {
            while (v[i]--) {
              char r = (char)(i + 'a');
              ans += r;
            }
          }
          cout << ans;
          return;
        }
      }
    }
  }
  cout << "-1";
}
int32_t main() {
  vrikodara();
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
