#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t, st;
  cin >> s >> t;
  bool bol = false, men = false;
  int a[26] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  for (int i = 0; i < s.size(); i++) {
    a[s[i] - (int)'a']++;
  }
  for (int i = 0; i < s.size(); i++) {
    if (men) {
      for (int j = 25; j >= 0; j--) {
        if (a[j] > 0) {
          a[j]--;
          s[i] = (char)(j + 'a');
          break;
        }
      }
      continue;
    }
    if (bol) {
      for (int j = 0; j < 26; j++) {
        if (a[j] > 0) {
          a[j]--;
          s[i] = (char)(j + 'a');
          break;
        }
      }
      continue;
    }
    int c = 0;
    for (int j = t[i] - (int)'a'; j < 26 && c == 0; j++) {
      if (a[j] != 0) {
        c++;
        c += (j == (t[i] - (int)'a'));
        a[j]--;
        s[i] = (char)(j + 'a');
      }
    }
    if (c == 0) {
      for (int j = t[i] - (int)'a'; j >= 0 && c == 0; j--) {
        if (a[j] > 0) {
          c++;
          a[j]--;
          s[i] = (char)(j + 'a');
        }
      }
      men = true;
      continue;
    }
    bol = (c == 1);
    if (i + 1 == t.size() && i + 1 != s.size()) bol = true;
    if (bol) bol = true;
  }
  if (s <= t) {
    while (next_permutation(s.begin(), s.end()) && s <= t) {
      int i = 1;
    }
    if (s <= t) {
      cout << "-1" << endl;
    } else
      cout << s << endl;
    return 0;
  }
  cout << s << endl;
  return 0;
}
