#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
char s[100009], t[100009];
int cnt[27];
void solve(int x, int k) {
  cnt[k]--;
  for (int i = 1; i < x; i++) printf("%c", t[i]);
  printf("%c", char(k + 97));
  for (int i = 0; i < 26; i++)
    while (cnt[i]--) printf("%c", char(i + 97));
  puts("");
  exit(0);
}
int main() {
  scanf("%s%s", s + 1, t + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) cnt[s[i] - 'a']++;
  int m = strlen(t + 1), no = 1;
  for (int i = 1; i <= m; i++) {
    if (!cnt[t[i] - 'a']) no = false;
    cnt[t[i] - 'a']--;
  }
  if (no and accumulate(cnt, cnt + 26, 0) > 0) {
    for (int i = 1; i <= m; i++) printf("%c", t[i]);
    for (int i = 0; i < 26; i++)
      while (cnt[i]--) printf("%c", char(97 + i));
    puts("");
    return 0;
  }
  for (int i = 1; i <= m; i++) cnt[t[i] - 'a']++;
  for (int i = m; i >= 1; i--) {
    int flag = 1, mark = 0;
    for (int j = 1; j < i; j++) {
      if (!cnt[t[j] - 'a']) flag = 0;
      cnt[t[j] - 'a']--;
    }
    for (int j = t[i] - 'a' + 1; j < 26; j++)
      if (cnt[j] >= 1) {
        mark = j;
        break;
      }
    if (flag and mark) solve(i, mark);
    for (int j = 1; j < i; j++) cnt[t[j] - 'a']++;
  }
  puts("-1");
  return 0;
}
