func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MN = 1000 * 100 + 10;   const int inf = (1 << 29);   string s, t, ans, tmp;   int cnt[30], curr[30];   int main() {     cin >> s >> t;     sort(s.rbegin(), s.rend());     for (int i = 0; i < s.size(); i++) cnt[s[i] -  a ]++;     if (s <= t)       cout <<  -1 n ;     else {       for (int i = t.size() - (t.size() == s.size()); i >= 0; i--) {         bool good = true;         for (int j = 0; j < 26; j++) curr[j] = cnt[j];         for (int j = 0; j < i; j++) {           curr[t[j] -  a ]--;           if (curr[t[j] -  a ] < 0) good = false;         }         if (!good) continue;         char c =  z  + 1;         if (i < t.size()) {           for (int j = 0; j < 26; j++)             if (curr[j] && j > t[i] -  a ) c = min(c, (char)(j +  a ));           if (c <=  z )             curr[c -  a ]--;           else             continue;         }         for (int j = 0; j < i; j++) ans.push_back(t[j]);         if (i < t.size()) ans.push_back(c);         for (int j = 0; j < 26; j++) {           while (curr[j]) {             ans.push_back((char)(j +  a ));             curr[j]--;           }         }         cout << ans << endl;         break;       }     }     return 0;   }   