#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long invMod(long long n) { return pwr(n, (1000000007LL) - 2); }
string str;
int n, cnt[5005][30], avail[30];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> str;
  for (int i = 0; i < (int)str.length(); i++) avail[str[i] - 'a']++;
  int len = str.length();
  cin >> str;
  n = str.length();
  cnt[0][str[0] - 'a']++;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];
    cnt[i][str[i] - 'a']++;
  }
  if (len > n) {
    bool impossible = false;
    for (int j = 0; j < 26; j++)
      if (cnt[n - 1][j] > avail[j]) impossible = true;
    if (impossible) goto lb;
    for (int i = 0; i < n; i++) {
      cout << str[i];
      avail[str[i] - 'a']--;
    }
    for (int i = 0; i < 26; i++)
      while (avail[i]--) cout << ((char)('a' + i));
    return 0;
  }
lb:
  int ans = -1;
  for (int i = n - 1; i >= 0; i--) {
    bool b = false;
    if (i != 0) {
      for (int j = 0; j < 26; j++)
        if (avail[j] < cnt[i - 1][j]) b = true;
    }
    if (b) continue;
    b = false;
    for (int j = str[i] - 'a' + 1; j < 26; j++)
      if (avail[j] > cnt[i - 1][j]) b = true;
    if (!b) continue;
    ans = i;
    break;
  }
  if (ans == -1) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < ans; i++) {
    cout << str[i];
    avail[str[i] - 'a']--;
  }
  for (int i = str[ans] - 'a' + 1; i < 26; i++)
    if (avail[i] > 0) {
      cout << ((char)(i + 'a'));
      avail[i]--;
      break;
    }
  for (int i = 0; i < 26; i++)
    while (avail[i]--) cout << ((char)(i + 'a'));
  return 0;
}
