#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) templateostream& operator<<(ostream& os,const pair&a){return os<<"("<void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<void chmin(T&a,const T&b){if(a>b)a=b;} templatevoid chmax(T&a,const T&b){if(a= 0; i--) { if (S[i] == 'a' + c) l = i; next[i][c] = l; } } } int main2() { string S, T; cin >> S >> T; const int N = S.size(); const int M = T.size(); make(S, nextS); make(T, nextT); // cout << S << endl; { B[S.size()] = T.size(); int j = T.size() - 1; for (int i = S.size() - 1; i >= 0; i--) { while (j >= 0 && S[i] != T[j]) j--; B[i] = j; } } // cout << T << endl; // pv(B, B+S.size() + 1); if (B[0] != -1) { cout << -1 << endl; return 0; } string ans = ""; int ii = 0, jj = 0; for (; ii < (int)S.size() && jj < (int)T.size(); ) { for (int c = 0; c < 26; c++) { int n_ii = nextS[ii][c]; int n_jj = nextT[jj][c]; if (n_ii >= (int)S.size()) continue; if (n_jj <= B[n_ii]) continue; ans += (char)('a' + c); ii = n_ii + 1; jj = n_jj; } } cout << ans << endl; return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }