#include <bits/stdc++.h>
using namespace std;
char s[5005], t[5005], r[5005];
int c[26] = {};
int main(void) {
  scanf("%s%s", s, t);
  for (int i = 0; s[i]; i++) c[s[i] - 'a']++;
  int i, j;
  for (i = 0; t[i] && s[i]; i++) {
    if (c[t[i] - 'a'] > 0) {
      c[t[i] - 'a']--;
      r[i] = t[i];
    } else
      break;
  }
  int win = 0;
  for (j = t[i] ? t[i] - 'a' : 0; j < 26; j++)
    if (c[j] > 0) {
      c[j]--;
      r[i++] = j + 'a';
      win = 1;
      break;
    }
  if (win) {
    for (; s[i]; i++) {
      for (j = 0; j < 26; j++)
        if (c[j]) {
          c[j]--;
          r[i] = j + 'a';
          break;
        }
    }
    puts(r);
  } else {
    for (; s[i]; i++)
      for (j = 25; j >= 0; j--)
        if (c[j]) {
          c[j]--;
          r[i] = j + 'a';
          break;
        }
    if (!next_permutation(r, r + i))
      puts("-1");
    else
      puts(r);
  }
  return 0;
}
