#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int f[26] = {0};
char result[5050];
string a, b;
int rs = 0;
bool dfs(int pos) {
  if (pos == b.size()) {
    bool ff = false;
    for (int j = 0; j < 26; j++) {
      for (int k = 0; k < f[j]; k++) {
        ff = true;
        result[rs++] = j + 'a';
      }
    }
    return ff;
  }
  int j = b[pos] - 'a';
  if (f[j]) {
    f[j]--;
    result[rs++] = j + 'a';
    if (dfs(pos + 1)) return true;
    rs--;
    f[j]++;
  }
  j = b[pos] - 'a' + 1;
  while (j < 26 && f[j] == 0) j++;
  if (j < 26) {
    f[j]--;
    result[rs++] = j + 'a';
    for (j = 0; j < 26; j++) {
      for (int k = 0; k < f[j]; k++) result[rs++] = j + 'a';
    }
    return true;
  }
  return false;
}
int main() {
  cin >> a >> b;
  for (int i = 0; i < a.size(); i++) {
    f[a[i] - 'a']++;
  }
  if (dfs(0)) {
    result[rs] = 0;
    cout << result << endl;
  } else
    cout << -1 << endl;
  return 0;
}
