#include <bits/stdc++.h>
using namespace std;
int n, m;
int vis[5005];
string p, q;
int cnt[26];
int ans[5005];
int isBigger() {
  for (int i = 1; i <= ans[0] && i - 1 < m; ++i) {
    if (ans[i] < q[i - 1] - 'a') return -1;
    if (ans[i] > q[i - 1] - 'a') return 1;
  }
  if (ans[0] == m)
    return 0;
  else if (ans[0] > m)
    return 1;
  else
    return -1;
}
bool dfs(int i) {
  int k = isBigger();
  if (k > 0) return true;
  if (i >= m) {
    if (k > 0)
      return true;
    else if (k == 0)
      return n > m;
    else if (k < 0)
      return false;
  }
  for (char c = q[i]; c <= 'z'; ++c) {
    if (cnt[c - 'a'] == 0) continue;
    --cnt[c - 'a'];
    ans[++ans[0]] = c - 'a';
    if (dfs(i + 1)) return true;
    --ans[0];
    ++cnt[c - 'a'];
  }
  return false;
}
int main() {
  cin >> p >> q;
  n = p.size();
  m = q.size();
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < n; ++i) ++cnt[p[i] - 'a'];
  ans[0] = 0;
  if (!dfs(0))
    printf("-1\n");
  else {
    for (int i = 1; i <= ans[0]; ++i) cout << (char)(ans[i] + 'a');
    for (int i = 0; i < 26; ++i)
      for (int j = 0; j < cnt[i]; ++j) cout << (char)(i + 'a');
    cout << endl;
  }
  return 0;
}
