#include <bits/stdc++.h>
using namespace std;
char s[5005], t[5005];
char ans[5005];
int letter[27], ls, lt, l;
bool search(int p) {
  if (p >= lt) {
    l = p;
    ans[p] = '\0';
    if (ls == lt) return false;
    return true;
  }
  if (letter[t[p] - 'a'] > 0) {
    letter[t[p] - 'a']--;
    ans[p] = t[p];
    if (search(p + 1)) return true;
    letter[t[p] - 'a']++;
  }
  for (int i = t[p] - 'a' + 1; i < 26; i++)
    if (letter[i] > 0) {
      ans[p] = i + 'a';
      ans[p + 1] = '\0';
      letter[i]--;
      l = p;
      return true;
    }
  return false;
}
void getans() {
  int i;
  if (l >= lt) l--;
  for (i = 0; i < 26; i++)
    while (letter[i]--) {
      ans[++l] = i + 'a';
    }
  ans[++l] = '\0';
  printf("%s\n", ans);
}
int main() {
  int i;
  while (scanf("%s %s", s, t) != EOF) {
    memset(letter, 0, sizeof(letter));
    ls = strlen(s);
    lt = strlen(t);
    for (i = 0; i < ls; i++) letter[s[i] - 'a']++;
    if (search(0)) {
      if (l < lt) {
        getans();
      } else if (ans[lt - 1] != t[lt - 1] || ls > lt) {
        getans();
      } else
        printf("-1\n");
    } else
      printf("-1\n");
  }
  return 0;
}
