#include <bits/stdc++.h>
using namespace std;
char second[5555];
char t[5555];
int n, m;
int cnt[5555][26];
int tcnt[26], ccnt[26];
int main() {
  scanf("%s", &second[1]);
  second[0] = '*';
  n = strlen(second) - 1;
  scanf("%s", &t[1]);
  t[0] = '*';
  m = strlen(t) - 1;
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j < 26; ++j) cnt[i][j] = cnt[i - 1][j];
    ++cnt[i][t[i] - 'a'];
  }
  for (int i = 1; i <= n; ++i) ++tcnt[second[i] - 'a'];
  if (n > m) {
    bool ok = true;
    for (int i = 0; i < 26; ++i) {
      ccnt[i] = tcnt[i] - cnt[m][i];
      if (ccnt[i] < 0) ok = false;
    }
    if (ok) {
      for (int i = 1; i <= m; ++i) putchar(t[i]);
      for (int i = 0; i < 26; ++i)
        for (int j = 0; j < ccnt[i]; ++j) putchar('a' + i);
      puts("");
      return 0;
    }
  }
  for (int i = m - 1; i >= 0; --i) {
    bool ok = true;
    for (int j = 0; j < 26; ++j) {
      ccnt[j] = tcnt[j] - cnt[i][j];
      if (ccnt[j] < 0) {
        ok = false;
        break;
      }
    }
    if (!ok) continue;
    ok = false;
    for (int j = t[i + 1] - 'a' + 1; j < 26; ++j)
      if (ccnt[j] > 0) {
        ok = true;
        break;
      }
    if (!ok) continue;
    for (int j = 1; j <= i; ++j) putchar(t[j]);
    for (int j = t[i + 1] - 'a' + 1; j < 26; ++j)
      if (ccnt[j] > 0) {
        putchar('a' + j);
        --ccnt[j];
        break;
      }
    for (int j = 0; j < 26; ++j)
      for (int k = 0; k < ccnt[j]; ++k) putchar('a' + j);
    puts("");
    return 0;
  }
  puts("-1");
  return 0;
}
