#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100009;
string s, t;
int chars[32];
void fillrest(int poz) {
  int i, j;
  j = 0;
  for (i = poz; i < s.length(); ++i) {
    while (chars[j] <= 0) {
      ++j;
    }
    s[i] = j + 'a';
    --chars[j];
  }
}
char searchGreaterThan(char which) {
  char c;
  for (c = which + 1; c <= 'z'; ++c) {
    if (chars[c - 'a'] > 0) {
      break;
    }
  }
  return c;
}
int main() {
  int i, j;
  char c;
  cin >> s >> t;
  for (i = 0; i < s.length(); ++i) {
    ++chars[s[i] - 'a'];
  }
  for (i = 0; i < t.length(); ++i) {
    if (chars[t[i] - 'a'] > 0) {
      --chars[t[i] - 'a'];
      s[i] = t[i];
    } else {
      for (; i >= 0; --i) {
        c = searchGreaterThan(t[i]);
        if (c <= 'z') {
          s[i] = c;
          --chars[c - 'a'];
          fillrest(i + 1);
          break;
        } else {
          if (i > 0) {
            ++chars[s[i - 1] - 'a'];
          }
        }
      }
      if (searchGreaterThan('a' - 1) <= 'z') {
        cout << -1 << endl;
      } else {
        cout << s << endl;
      }
      return 0;
    }
  }
  if (t.length() <= s.length()) {
    t.push_back('a' - 1);
    for (; i >= 0; --i) {
      c = searchGreaterThan(t[i]);
      if (c <= 'z') {
        s[i] = c;
        --chars[c - 'a'];
        fillrest(i + 1);
        break;
      } else {
        if (i > 0) {
          ++chars[s[i - 1] - 'a'];
        }
      }
    }
    if (searchGreaterThan('a' - 1) <= 'z') {
      cout << -1 << endl;
    } else {
      cout << s << endl;
    }
  }
  return 0;
}
