#include <bits/stdc++.h>
using namespace std;
string s, t;
int ns, nt;
char ans[10000];
int countInS[26];
bool dfs(int x) {
  if (x == nt && nt < ns) {
    for (int i = 0; i < (26); ++i)
      while (countInS[i]--) ans[x++] = char('a' + i);
    ans[x] = '\0';
    cout << ans << endl;
    exit(0);
  } else if (x == ns) {
    ans[x] = '\0';
    string ss(ans);
    next_permutation((ss).begin(), (ss).end());
    if (ss > t) {
      cout << ss << endl;
      exit(0);
    } else
      return false;
  }
  bool tag = false;
  if (countInS[t[x] - 'a']) {
    --countInS[t[x] - 'a'];
    ans[x] = t[x];
    tag = dfs(x + 1);
    ++countInS[t[x] - 'a'];
  }
  if (!tag) {
    for (int i = 0; i < (26); ++i)
      if (i > t[x] - 'a' && countInS[i]) {
        --countInS[i];
        ans[x++] = char(i + 'a');
        for (int j = 0; j < (26); ++j)
          while (countInS[j]--) ans[x++] = char(j + 'a');
        ans[x] = '\0';
        cout << ans << endl;
        exit(0);
      }
    return false;
  }
  return true;
}
int main(void) {
  cin >> s >> t;
  ns = s.size();
  nt = t.size();
  for (int i = 0; i < (ns); ++i) ++countInS[s[i] - 'a'];
  dfs(0);
  cout << -1 << endl;
  return 0;
}
