#include <bits/stdc++.h>
using namespace std;
string s, t;
long long int co[26];
string solve(long long int pos) {
  long long int cur[26] = {};
  string ans = t.substr(0, pos);
  for (long long int i = 0; i < pos; i++) cur[t[i] - 'a']++;
  for (long long int i = 0; i < 26; i++)
    if (cur[i] > co[i]) return "";
  for (long long int i = t[pos] - 'a' + 1; i < 26; ++i)
    if (co[i] - cur[i] > 0) {
      cur[i]++;
      ans.push_back(i + 'a');
      break;
    }
  for (long long int i = 0; i < 26; i++)
    while (cur[i] < co[i]) {
      ans.push_back(i + 'a');
      cur[i]++;
    }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s >> t;
  sort(s.begin(), s.end());
  if (s > t) {
    cout << s << endl;
    return 0;
  }
  reverse(s.begin(), s.end());
  if (s <= t) {
    cout << "-1" << endl;
    return 0;
  }
  for (long long int i = 0; i < s.size(); i++) co[s[i] - 'a']++;
  t.push_back('a' - 1);
  for (long long int i = t.size() - 1; i >= 0; i--) {
    string cur = solve(i);
    if (cur > t) {
      cout << cur << endl;
      return 0;
    }
  }
}
