#include <bits/stdc++.h>
using namespace std;
const int N = 203600;
char s[N], t[N];
int n, m;
int b[256], b2[256];
int main() {
  scanf("%s%s", s, t);
  n = strlen(s);
  m = strlen(t);
  string ans = "";
  for (int i = (0); i < (int)(n); i++) b[s[i]]++;
  for (int j = min(n, m); j >= 0; j--) {
    string tmp = "";
    for (int first = ('a'); first <= (int)('z'); first++) b2[first] = b[first];
    bool ok = true;
    for (int second = (0); second < (int)(j); second++) {
      if (b2[t[second]] <= 0) {
        ok = false;
        break;
      }
      tmp += t[second];
      b2[t[second]]--;
    }
    if (!ok) continue;
    int first = t[j] + 1;
    while (first <= 'z' && b2[first] == 0) ++first;
    if (first > 'z') continue;
    tmp += first;
    b2[first]--;
    for (int first = ('a'); first <= (int)('z'); first++) {
      while (b2[first]--) {
        tmp += first;
      }
    }
    if (tmp > t) {
      ans = tmp;
      break;
    }
  }
  if (ans == "")
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
