#include <bits/stdc++.h>
using namespace std;
void calc(char *s, int *sum) {
  for (int i = (0); i < (26); i++) sum[i] = 0;
  int len = strlen(s);
  for (int i = (0); i < (len); i++) {
    sum[s[i] - 'a']++;
  }
}
char s[110000], t[110000];
int main() {
  while (scanf("%s %s", s, t) != EOF) {
    int second[26], st[26];
    calc(s, second);
    calc(t, st);
    bool can = true;
    int more = 0;
    for (int i = (0); i < (26); i++) {
      if (second[i] < st[i]) can = false;
      if (second[i] > st[i]) more++;
    }
    if (can && more > 0) {
      int cnt = strlen(t);
      for (int i = (0); i < (26); i++)
        if (second[i] > st[i]) {
          for (int j = (0); j < (second[i] - st[i]); j++) t[cnt++] = 'a' + i;
        }
      t[cnt] = 0;
      cout << t << endl;
      continue;
    }
    int lent = strlen(t);
    for (int i = lent - 1; i >= 0; i--) {
      st[t[i] - 'a']--;
      bool can = true;
      for (int j = (0); j < (26); j++)
        if (second[j] < st[j]) can = false;
      if (can == false) continue;
      bool flag = false;
      for (int j = (0); j < (26); j++)
        if (j > t[i] - 'a' && second[j] > st[j]) {
          flag = true;
          second[j]--;
          t[i] = 'a' + j;
          int cnt = i + 1;
          for (int i = (0); i < (26); i++)
            if (second[i] > st[i]) {
              for (int j = (0); j < (second[i] - st[i]); j++)
                t[cnt++] = 'a' + i;
            }
          t[cnt] = 0;
          cout << t << endl;
          break;
        }
      if (flag) return 0;
    }
    cout << -1 << endl;
  }
  return 0;
}
