#include <bits/stdc++.h>
int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};
using namespace std;
template <class T>
T sq(T n) {
  return n * n;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
bool inside(T a, T b, T c) {
  return a <= b && b <= c;
}
template <class T>
void setmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
char A[5010];
char B[5010];
char ans[5010];
int cnt[510];
int a, b, l;
int cal(int pos) {
  if (pos == a) return -(1 << 29);
  if (pos == b) return pos;
  int i, j;
  int cur[27];
  for (j = 'a'; j < 'z' + 1; j++) cur[j - 'a'] = cnt[j];
  for (i = 0; i < pos; i++) cur[B[i] - 'a']--;
  int ret = -(1 << 29);
  if (cur[B[pos] - 'a']) ret = cal(pos + 1);
  for (j = B[pos] + 1; j < 'z' + 1; j++)
    if (cur[j - 'a']) {
      ret = max(ret, pos);
      break;
    }
  return ret;
}
int main() {
  int n, t = 1, m, i, j, k, last;
  scanf("%s", A);
  scanf("%s", B);
  for (i = 0; A[i]; i++) cnt[A[i]]++;
  a = i;
  b = strlen(B);
  k = cal(0);
  if (k < 0) {
    puts("-1");
    return 0;
  }
  l = 0;
  for (i = 0; i < k; i++) {
    ans[l++] = B[i];
    cnt[B[i]]--;
  }
  for (j = B[k] + 1; j < 'z' + 1; j++)
    if (cnt[j]) {
      ans[l++] = j;
      cnt[j]--;
      break;
    }
  for (j = 'a'; j < 'z' + 1; j++)
    while (cnt[j]--) ans[l++] = j;
  ans[l] = 0;
  puts(ans);
  return 0;
}
