#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const double EPS = 1e-8;
int c[26];
char s[N], t[N];
void count(int n, char s[], int c[]) {
  memset(c, 0, sizeof(c[0]) * 26);
  for (int i = (0); i < (n); ++i) ++c[s[i] - 'a'];
}
void solve() {
  int n = strlen(s), m = strlen(t), L = -1, last = -1;
  count(n, s, c);
  for (int i = (0); i < (min(n, m)); ++i) {
    for (int j = (t[i] - 'a' + 1); j < (26); ++j)
      if (c[j] > 0) {
        L = i;
        break;
      }
    if (!c[t[i] - 'a']) break;
    --c[t[i] - 'a'], last = i;
  }
  if (n > m && last == m - 1) L = m;
  if (L == -1) {
    puts("-1");
    return;
  }
  count(n, s, c);
  for (int i = (0); i < (L); ++i) putchar(t[i]), --c[t[i] - 'a'];
  for (int j = (0); j < (26); ++j)
    if (c[j] > 0 && ('a' + j) > t[L]) {
      putchar('a' + j), --c[j];
      break;
    }
  for (int i = (L + 1); i < (n); ++i)
    for (int j = (0); j < (26); ++j)
      if (c[j] > 0) {
        putchar('a' + j), --c[j];
        break;
      }
}
int main() {
  scanf("%s %s", s, t);
  solve();
  return 0;
}
