#include <bits/stdc++.h>
using namespace std;
int n, m, a[5010], b[5010];
int Cnt[300];
char s[5010];
void Init() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) a[i] = s[i];
  scanf("%s", s + 1);
  m = strlen(s + 1);
  for (int i = 1; i <= m; ++i) b[i] = s[i];
  b[m + 1] = -1;
}
void Solve() {
  int ans = -1, x = min(n, m) + 1;
  for (int i = 1; i <= n; ++i) ++Cnt[a[i]];
  for (int i = 1; i <= x; ++i) {
    for (int j = 0; j <= 255; ++j)
      if (j > b[i] && Cnt[j]) ans = i - 1;
    if (i > m || !Cnt[b[i]]) break;
    --Cnt[b[i]];
  }
  if (ans == -1) {
    printf("-1\n");
    return;
  }
  memset(Cnt, 0, sizeof(Cnt));
  for (int i = 1; i <= n; ++i) ++Cnt[a[i]];
  for (int i = 1; i <= ans; ++i) {
    printf("%c", b[i]);
    --Cnt[b[i]];
  }
  for (int i = 0; i <= 255; ++i)
    if (i > b[ans + 1] && Cnt[i]) {
      printf("%c", i);
      --Cnt[i];
      break;
    }
  for (int i = 0; i <= 255; ++i)
    for (int j = 1; j <= Cnt[i]; ++j) printf("%c", i);
  printf("\n");
}
int main() {
  Init();
  Solve();
  return 0;
}
