#include <bits/stdc++.h>
const int N = 5000 + 10;
char s[N], t[N];
int app[N][30];
int tot[30];
int idx(char c) {
  if (c >= 'a' && c <= 'z')
    return c - 'a' + 1;
  else
    return 0;
}
int lens, lent;
int main() {
  scanf("%s%s", s, t);
  lens = strlen(s);
  lent = strlen(t);
  while (lent < lens) t[lent++] = ']';
  for (int i = 0; i < lens; ++i) ++tot[idx(s[i])];
  for (int i = 0; i < lent; ++i) {
    if (i)
      for (int j = 0; j < 30; ++j) app[i][j] = app[i - 1][j];
    ++app[i][idx(t[i])];
  }
  int pos = -1;
  for (int j = 0; j < 30; ++j)
    if (tot[j] > 0 && j > idx(t[0])) {
      pos = 0;
      break;
    }
  for (int i = 1; i < lens; ++i) {
    bool done = true;
    for (int j = 0; j < 30; ++j)
      if (tot[j] - app[i - 1][j] < 0) done = false;
    if (done) {
      int c = idx(t[i]);
      for (int j = c + 1; j < 30; ++j)
        if (tot[j] - app[i - 1][j] > 0) {
          pos = i;
          break;
        }
    } else
      break;
  }
  if (pos == -1)
    printf("%d\n", pos);
  else {
    for (int i = 0; i < pos; ++i) putchar(t[i]);
    if (pos > 0)
      for (int j = 0; j < 30; ++j) tot[j] -= app[pos - 1][j];
    for (int j = 0; j < 30; ++j)
      if (j > idx(t[pos]) && tot[j] > 0) {
        putchar('a' + j - 1);
        --tot[j];
        break;
      }
    for (int j = 1; j < 30; ++j)
      while (tot[j] > 0) {
        --tot[j];
        putchar(j + 'a' - 1);
      }
    puts("");
  }
  return 0;
}
