#include <bits/stdc++.h>
using namespace std;
void ritikio();
const long long int inff = LLONG_MAX;
const long long int minff = LLONG_MIN;
const long long int inf = 1e18;
const long long int pmod = 998244353;
const long long int mod = 1e9 + 7;
const long long int maxm = 2e6 + 3;
const long long int maxN = 1e5 + 3;
long long int find(long long int indx, vector<long long int>& v) {
  long long int f = -1;
  long long int n = (long long int)v.size();
  for (long long int i = indx; i < n; i++) {
    if (v[i] > 0) {
      f = i;
      break;
    }
  }
  return f;
}
void solve() {
  string s, t;
  cin >> s >> t;
  long long int n = s.length(), m = t.length();
  vector<long long int> v1(27);
  for (long long int i = 0; i < n; i++) v1[s[i] - 'a']++;
  string ans = s;
  for (long long int i = 0; i < n; i++) {
    long long int f = 0;
    for (long long int lt = 0; lt < 26; lt++) {
      if (v1[lt] == 0) continue;
      ans[i] = 'a' + lt;
      v1[lt]--;
      long long int pos = i + 1;
      for (long long int j = 25; j > -1; j--) {
        for (long long int k = 0; k < v1[j]; k++) ans[pos++] = 'a' + j;
      }
      if (ans > t) {
        f = 1;
        break;
      }
      v1[lt]++;
    }
    if (f == 0) {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}
signed main() {
  ritikio();
  long long int T = 1;
  while (T--) {
    solve();
  }
}
void ritikio() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
