func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 5001;   const int B = 27;   int zhu[B], n, m;   char s[N], t[N];   void solve() {     memset(zhu, 0, sizeof(zhu));     n = strlen(s);     m = strlen(t);     for (int i = 0; i < n; ++i) zhu[s[i] -  a ]++;     int r = -1, p;     if (n > m)       p = m;     else       p = min(n, m) - 1;     for (int i = t[0] -  a  + 1; i < 26; ++i)       if (zhu[i]) r = 0;     for (int i = 1; i <= p; ++i) {       zhu[t[i - 1] -  a ]--;       if (zhu[t[i - 1] -  a ] < 0) break;       if (i == m) {         r = m;         continue;       }       for (int j = t[i] -  a  + 1; j < 26; ++j)         if (zhu[j]) r = i;     }     if (r == -1) {       printf( -1 n );       return;     } else {       memset(zhu, 0, sizeof(zhu));       for (int i = 0; i < n; ++i) zhu[s[i] -  a ]++;       for (int i = 0; i < r; ++i) {         printf( %c , t[i]);         zhu[t[i] -  a ]--;       }       if (r < m)         for (int i = t[r] -  a  + 1; i < 26; ++i)           if (zhu[i]) {             printf( %c , i +  a );             zhu[i]--;             break;           }       for (int i = 0; i < 26; ++i)         while (zhu[i]--) printf( %c , i +  a );       printf(  n );     }   }   int main() {     while (~scanf( %s%s , s, t)) solve();   }   