#include <bits/stdc++.h>
using namespace std;
string s, t, out;
int a[26] = {0};
int used[26] = {0};
int find(int start) {
  bool ok = false;
  for (int j = start; j < 26; ++j) {
    if (a[j]) {
      out.push_back(j + 'a');
      --a[j];
      for (int i = 0; i < 26; ++i) {
        out += string(a[i], i + 'a');
        a[i] = 0;
      }
      return true;
    }
  }
  return false;
}
void solve() {
  cin >> s;
  cin >> t;
  for (int i = 0; i < s.size(); ++i) {
    ++a[s[i] - 'a'];
  }
  for (int i = 0; i < t.size(); ++i) {
    if (a[t[i] - 'a']) {
      out.push_back(t[i]);
      --a[t[i] - 'a'];
    } else {
      while (!find(t[i] - 'a' + 1)) {
        if (out.size()) {
          ++a[out[out.size() - 1] - 'a'];
          out.resize(out.size() - 1);
          --i;
        } else {
          printf("-1\n");
          return;
        }
      }
      cout << out << endl;
      return;
    }
  }
  if (out.size() < s.size()) {
    for (int i = 0; i < 26; ++i) {
      if (a[i]) {
        out += string(a[i], i + 'a');
      }
    }
    cout << out << endl;
  } else if (next_permutation(out.begin(), out.end())) {
    cout << out << endl;
  } else {
    printf("-1\n");
  }
}
int main() {
  solve();
  return 0;
}
