Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner.

Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep up with the neighbours, they decided to call the baby so that the name was lexicographically strictly larger than the neighbour's son's name t.

On the other hand, they suspect that a name tax will be introduced shortly. According to it, the Taucetians with lexicographically larger names will pay larger taxes. That's the reason abac and bbad want to call the newborn so that the name was lexicographically strictly larger than name t and lexicographically minimum at that.

The lexicographical order of strings is the order we are all used to, the "dictionary" order. Such comparison is used in all modern programming languages to compare strings. Formally, a string p of length n is lexicographically less than string q of length m, if one of the two statements is correct:

  * n < m, and p is the beginning (prefix) of string q (for example, "aba" is less than string "abaa"), 
  * p1 = q1, p2 = q2, ..., pk - 1 = qk - 1, pk < qk for some k (1 ≤ k ≤ min(n, m)), here characters in strings are numbered starting from 1. 



Write a program that, given string s and the heighbours' child's name t determines the string that is the result of permutation of letters in s. The string should be lexicographically strictly more than t and also, lexicographically minimum.

Input

The first line contains a non-empty string s (1 ≤ |s| ≤ 5000), where |s| is its length. The second line contains a non-empty string t (1 ≤ |t| ≤ 5000), where |t| is its length. Both strings consist of lowercase Latin letters.

Output

Print the sought name or -1 if it doesn't exist.

Examples

Input

aad
aac


Output

aad


Input

abad
bob


Output

daab


Input

abc
defg


Output

-1


Input

czaaab
abcdef


Output

abczaa

Note

In the first sample the given string s is the sought one, consequently, we do not need to change the letter order there.
z
a
 abc
aaac
 bcbcdddbbd
bcbcdbdbbd
 aaabccadac
acabbbabaa
 a
b
 acaccaaadz
caadccaaaa
 aa
ab
 abacaba
aba
 aabbaa
aaaaaaaaaaaaaaaaaaaa
 ac
a
 a
a
 aabbaa
caaaaaaaaa
 aaaaaaaaa
a
 ccc
cc
 acbdcbacbb
cbcddabcbdaccdd
 zaaa
aaaw
 bbbaabbaab
bbbaabbaab
 z
ww
 acaccaaadd
acaccaaadd
 aabbaa
a
 ccabcaabcc
bcca
 adbddbccdacbaab
adaddcbddb
 abc
caa
 ab
b
 aa
aa
 zzzzzzzzzzzz
a
 aa
a
 abc
cac
 aaaaaaaaz
wwwwwwwwwwwwwwwwwwww
 ab
aa
 aaa
aa
 aab
aa
 zzzzzzzzzz
aaaaaaaaa
 bbbaabbaaz
abaabbbbaa
 bbbaabbaab
ababbaaabb
 bcbcdddbbd
abbbcbdcdc
 abbabaaabaaabbbbabbbbbababababaaaabbabbbbabbbbbabbbbababbaaaaabbbabbbbabbbbbbabaabababaabbbabababbaz
abaaabaabbbbaabbbbaabababbaabaabababbbaabbbaaabbabbabbbbbbbbaabbbbbabababbbbaaabaaaabbbbbbbbabababba
 abab
aaba
 abcabc
aaccba
 bcbcdddbbz
dbbccbddba
 bbbbaacacb
cbacbaabb
 adbddbccdacbaab
adcddbdcda
 abc
bbb
 z
anana
 adbddbccdacbaaz
dacdcaddbb
 abc
aca
 babbaccbab
b
 abc
abbc
 aaaaaaaaaaaaaaa
aaaaaaaaaaaaaa
 acaccaaadd
babcacbadd
 abacaba
abababa
 abbabaaabaaabbbbabbbbbababababaaaabbabbbbabbbbbabbbbababbaaaaabbbabbbbabbbbbbabaabababaabbbabababbaa
abbabaaabaaabbbbabbbabababababaaaabbabbbbabbbbbabbbbababbaaaaabbaabbbbabbbbbbabaabababaabbbabababbaa
 abbabaaabaaabbbbabbbbbababababaaaabbabbbbabbbbbabbbbababbaaaaabbbabbbbabbbbbbabaabababaabbbabababbaa
bbaabaabaaaabbabaaaababababaabaabaaaabbaabbbbabbbaabaabaababbaababaaaabababbaabbaaabbbaaaaaaabaabbbb
 aaabccadac
aabbccbdac
 bbbcaabcaa
cacbababab
 aaabccadaz
acabcaadaa
 qwertyz
qwertyuiop
 ab
a
 abc
aabb
 abcabc
abccaa
 z
zz

z
 abc
 bcbcdbdbdd
 acabcaaacd
 -1
 caadccaaaz
 -1
 abaaabc
 aaaabb
 ac
 -1
 -1
 aaaaaaaaa
 ccc
 cbdaabbbcc
 aaaz
 bbbaabbaba
 z
 acaccaadad
 aaaabb
 bccaaabccc
 adaddccaabbbbcd
 cab
 ba
 -1
 zzzzzzzzzzzz
 aa
 cba
 zaaaaaaaa
 ab
 aaa
 aab
 zzzzzzzzzz
 abaabbbbaz
 ababbaabbb
 bbbbccdddd
 abaaabaabbbbaabbbbaabababbaabaabababbbaabbbaaabbabbabbbbbbbbaabbbbbabababbbbaaabaaaabbbbbbbbabababbz
 aabb
 aaccbb
 dbbccbddbz
 cbacbaabbb
 adcddcaaabbbbcd
 bca
 z
 dacdcaddbbaabcz
 acb
 baaabbbbcc
 abc
 aaaaaaaaaaaaaaa
 caaaaaccdd
 ababaca
 abbabaaabaaabbbbabbbabababababaaaabbabbbbabbbbbabbbbababbaaaaabbaabbbbabbbbbbabaabababaabbbabababbbb
 bbaabaabaaaabbabaaaababababaabaabaaaabbaabbbbabbbaabaabaababbaababaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
 aabcaaaccd
 cacbababba
 acabcaadaz
 qwertyz
 ab
 abc
 abccab
 -1

#include <bits/stdc++.h>
using namespace std;
signed main() {
  std::ios_base::sync_with_stdio(0), cin.tie(0);
  string s, t;
  cin >> s >> t;
  int a[26] = {};
  int n = s.size(), m = t.size();
  for (int i = 0; i < n; ++i) a[s[i] - 'a']++;
  bool ok = 0;
  if (n < m) {
    s = "";
    for (int i = 0; i < n && !ok; ++i) {
      if (a[t[i] - 'a']) {
        a[t[i] - 'a']--;
        s += t[i];
        continue;
      } else {
        for (int j = t[i] - 'a' + 1; j < 26; ++j) {
          if (a[j]) {
            a[j]--;
            s += char('a' + j);
            ok = 1;
            break;
          }
        }
        if (ok) break;
        for (int j = i - 1; j >= 0 && !ok; --j) {
          a[s[j] - 'a']++;
          s.pop_back();
          for (int k = t[j] - 'a' + 1; k < 26; ++k) {
            if (a[k]) {
              a[k]--;
              s += char(k + 'a');
              ok = 1;
              break;
            }
          }
        }
        if (!ok) {
          cout << -1;
          return 0;
        }
      }
    }
    if (!ok) {
      cout << -1;
      return 0;
    }
    for (int i = 0; i < 26; ++i) {
      for (int j = 0; j < a[i]; ++j) {
        s += char('a' + i);
      }
    }
    cout << s;
    return 0;
  }
  s = "";
  for (int i = 0; i < m && !ok; ++i) {
    if (a[t[i] - 'a']) {
      a[t[i] - 'a']--;
      s += t[i];
      continue;
    } else {
      for (int j = t[i] - 'a' + 1; j < 26; ++j) {
        if (a[j]) {
          a[j]--;
          s += char('a' + j);
          ok = 1;
          break;
        }
      }
      if (ok) break;
      for (int j = i - 1; j >= 0 && !ok; --j) {
        a[s[j] - 'a']++;
        s.pop_back();
        for (int k = t[j] - 'a' + 1; k < 26; ++k) {
          if (a[k]) {
            a[k]--;
            s += char(k + 'a');
            ok = 1;
            break;
          }
        }
      }
      if (!ok) {
        cout << -1;
        return 0;
      }
    }
  }
  if (!ok) {
    if (n == m) {
      if (next_permutation(s.begin(), s.end()))
        cout << s;
      else
        cout << -1;
      return 0;
    }
  }
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < a[i]; ++j) {
      s += char('a' + i);
    }
  }
  cout << s;
  return 0;
}
