#include <bits/stdc++.h>
using namespace std;
const int size = 100000 + 10;
char s[size], t[size], s1[size];
int num1[30], num2[30], flag = 0;
int main() {
  cin >> s >> t;
  memset(num1, 0, sizeof(num1));
  for (int i = 0; i < strlen(s); i++) num1[s[i] - 'a']++;
  int i, j;
  for (i = 0; s[i] && t[i]; i++)
    if (num1[t[i] - 'a'] > 0)
      num1[t[i] - 'a']--, s1[i] = t[i];
    else
      break;
  j = t[i] ? t[i] - 'a' : 0;
  for (j; j < 26; j++)
    if (num1[j] > 0) {
      num1[j]--, s1[i++] = j + 'a';
      flag = 1;
      break;
    }
  if (flag) {
    for (; s[i]; i++)
      for (j = 0; j < 26; j++)
        if (num1[j]) {
          num1[j]--, s1[i] = j + 'a';
          break;
        }
    puts(s1);
  } else {
    for (; s[i]; i++)
      for (j = 25; j >= 0; j--)
        if (num1[j]) {
          num1[j]--, s1[i] = j + 'a';
          break;
        }
    if (!next_permutation(s1, s1 + i))
      puts("-1");
    else
      puts(s1);
  }
  return 0;
}
