#include #include #include #include #include #include #include using namespace std; typedef long long ll; string S, T; int substr_idx[100000]; int next_t[100005][26]; int next_s[100005][26]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> S >> T; int cur_t = T.size()-1; for(int i = S.size()-1; i >= 0; i--){ while(cur_t >= 0){ if(T[cur_t] == S[i]) break; cur_t--; } substr_idx[i] = cur_t; if(cur_t >= 0) cur_t--; } if(substr_idx[0] != -1){ cout << -1 << endl; return 0; } // T for(int i = 0; i < 26; i++){ next_t[T.size()-1][i] = T.size(); } next_t[T.size()-1][T[T.size()-1]-'a'] = T.size()-1; for(int i = T.size()-1; i >= 0; i--){ if(i == T.size()-1) continue; for(int j = 0; j < 26; j++){ next_t[i][j] = next_t[i+1][j]; } next_t[i][T[i]-'a'] = i; } // S for(int i = 0; i < 26; i++){ next_s[S.size()-1][i] = S.size(); } next_s[S.size()-1][S[S.size()-1]-'a'] = S.size()-1; for(int i = S.size()-1; i >= 0; i--){ if(i == S.size()-1) continue; for(int j = 0; j < 26; j++){ next_s[i][j] = next_s[i+1][j]; } next_s[i][S[i]-'a'] = i; } int cur_s = 0; cur_t = 0; string ans; while(true){ if(cur_t > T.size()) break; if(cur_t >= T.size()) { for(int i = 0; i < 26; i++){ char c = 'a'+i; int s = next_s[cur_s][i]; if(s < S.size()){ ans += c; break; } } break; } for(int i = 0; i < 26; i++){ int s = next_s[cur_s][i]; int t = next_t[cur_t][i]; char c = 'a'+i; if(s < S.size() && t == T.size()) { cur_t = t+1; ans += c; break; } if(s < S.size() && substr_idx[s] < t){ ans += c; cur_s = s+1; cur_t = t+1; break; } } } cout << ans << endl; }