#include <bits/stdc++.h>
using namespace std;
int c[30];
int main() {
  string s, t, ans = "";
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++) {
    c[s[i] - 'a']++;
    ans += 'z';
  }
  for (int i = 0; i < t.length(); i++) {
    ans += 'z';
  }
  string pre = "";
  int pos = 0;
  for (int i = 0; i < t.length(); i++) {
    int v = t[i] - 'a', x = -1;
    for (int j = v + 1; j < 26; j++) {
      if (c[j]) {
        x = j;
        break;
      }
    }
    if (x != -1) {
      string now = pre;
      now += (char)(x + 'a');
      for (int j = 0; j < 26; j++) {
        for (int k = 1; k <= c[j] - (j == x); k++) {
          now += (char)(j + 'a');
        }
      }
      ans = min(ans, now);
    }
    if (c[v]) {
      pre += (char)(v + 'a');
      c[v]--;
      pos++;
    } else
      break;
  }
  if (pos == t.length() && pos < s.length()) {
    string now = pre;
    for (int j = 0; j < 26; j++) {
      for (int k = 1; k <= c[j]; k++) {
        now += (char)(j + 'a');
      }
    }
    ans = min(ans, now);
  }
  if (ans.length() > s.length())
    cout << -1 << endl;
  else
    cout << ans << endl;
}
