#include <bits/stdc++.h>
char s[10005], t[10005];
int cnt[10005], pre[10005], lent, lens;
bool ok;
int gen(int p, char x) {
  for (int i = 0; i <= p; ++i) printf("%c", t[i]);
  if (x != '#') {
    printf("%c", x);
    pre[x - 'a']--;
  }
  for (int i = 0; i < 26; ++i)
    for (int j = 1; j <= pre[i]; ++j) printf("%c", i + 'a');
  puts("");
}
int dfs(int dep) {
  if (dep >= lent) {
    if (lens == lent) return 0;
    ok = true;
    gen(dep - 1, '#');
    return 0;
  }
  if (pre[t[dep] - 'a']) {
    pre[t[dep] - 'a']--;
    dfs(dep + 1);
    pre[t[dep] - 'a']++;
    if (ok) return 0;
  }
  int zz = t[dep] - 'a';
  for (int i = zz + 1; i < 26; ++i)
    if (pre[i]) {
      gen(dep - 1, i + 'a');
      ok = true;
      return 0;
    }
  return 0;
}
int main() {
  scanf("%s", s);
  scanf("%s", t);
  lent = strlen(t);
  lens = strlen(s);
  for (int i = 0; i < lens; ++i) pre[s[i] - 'a']++;
  ok = false;
  dfs(0);
  if (!ok) puts("-1");
}
