#include <bits/stdc++.h>
using namespace std;
string a, b, c;
string ans, temp;
int cnt[30];
int tcnt[30];
void con(int i, int n, int m) {
  memset(tcnt, 0, sizeof tcnt);
  if (i >= n) {
    return;
  }
  bool q = 0;
  if (i < m)
    for (int j = b[i] - 'a' + 1; j < 30; j++) {
      if (cnt[j] > tcnt[j]) {
        q = 1;
        temp[i] = j + 'a';
        tcnt[j]++;
        i++;
        break;
      }
    }
  else {
    q = 1;
  }
  if (!q) {
    temp = c;
    return;
  }
  while (i < n) {
    for (int j = 0; j < 30; j++) {
      if (cnt[j] > tcnt[j]) {
        tcnt[j]++;
        temp[i] = j + 'a';
        break;
      }
    }
    i++;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> a >> b;
  c = a;
  int m = b.size();
  sort(c.rbegin(), c.rend());
  if (c <= b) {
    cout << -1 << endl;
    return 0;
  }
  int n = a.size();
  for (int i = 0; i < n; i++) cnt[a[i] - 'a']++;
  temp = c;
  ans = c;
  con(0, n, m);
  ans = temp;
  for (int i = 0; i < min(n, m); i++) {
    if (cnt[b[i] - 'a']) {
      cnt[b[i] - 'a']--;
      for (int j = 0; j <= i; j++) temp[j] = b[j];
      con(i + 1, n, m);
      if (temp < ans && temp != b) ans = temp;
    } else
      break;
  }
  cout << ans << endl;
  return 0;
}
