#include <bits/stdc++.h>
using namespace std;
const int N = 256;
int cnt[N];
string s, t;
bool dfs(string& s, int pos, bool large) {
  if (pos == t.length()) return large || ::s.length() > t.length();
  if (large == false) {
    if (cnt[t[pos]]) {
      cnt[t[pos]]--;
      s += t[pos];
      if (!dfs(s, pos + 1, 0)) {
        s.erase(s.end() - 1);
        cnt[t[pos]]++;
        for (char c = t[pos] + 1; c <= 'z'; c++) {
          if (cnt[c] == 0) continue;
          cnt[c]--;
          s += c;
          return dfs(s, pos + 1, 1);
        }
        return false;
      } else {
        return true;
      }
    } else {
      for (char c = t[pos] + 1; c <= 'z'; c++) {
        if (cnt[c] == 0) continue;
        cnt[c]--;
        s += c;
        return dfs(s, pos + 1, 1);
      }
      return false;
    }
  } else {
    for (char c = 'a'; c <= 'z'; c++) {
      if (cnt[c] == 0) continue;
      cnt[c]--;
      s += c;
      return dfs(s, pos + 1, 1);
    }
    return true;
  }
}
int main() {
  while (cin >> s >> t) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < s.length(); i++) {
      cnt[s[i]]++;
    }
    string ans;
    if (dfs(ans, 0, false)) {
      for (int i = 'a'; i <= 'z'; i++) {
        for (int j = 0; j < cnt[i]; j++) {
          ans += i;
        }
      }
      cout << ans << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
