#include <bits/stdc++.h>
using namespace std;
string s, t;
int n, m;
vector<int> A(26, 0), B;
string str;
bool poss(int till) {
  str = "";
  B = A;
  for (int i = 0; i < till; i++) {
    if (B[t[i] - 'a'] == 0) return false;
    B[t[i] - 'a']--;
    str += t[i];
  }
  if (till == n) return false;
  if (till < m) {
    bool found = false;
    for (int i = t[till] - 'a' + 1; i < 26; i++) {
      if (B[i] != 0) {
        str += ('a' + i);
        B[i]--;
        found = true;
        break;
      }
    }
    if (!found) return false;
  }
  for (int i = 0; i < 26; i++) {
    str += string(B[i], 'a' + i);
  }
  return true;
}
int main() {
  cin >> s >> t;
  n = s.size(), m = t.size();
  int k = min(n, m);
  for (int i = 0; i < n; i++) {
    A[s[i] - 'a']++;
  }
  if (n >= m) {
    if (poss(m)) {
      if (str != t) {
        cout << str << endl;
        return 0;
      }
    }
  }
  for (int fd = k; fd >= 0; fd--) {
    if (poss(fd)) {
      cout << str << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
