#include #include #include using namespace std; const int alphabet_size = 26; int main() { string s, t; cin >> s >> t; int ss = s.size(), ts = t.size(); vector> s_next(ss + 1, vector(alphabet_size, ss)); for (int i = ss - 1; i >= 0; --i) { for (int j = 0; j < alphabet_size; ++j) { s_next[i][j] = s_next[i + 1][j]; } s_next[i][s[i] - 'a'] = i; } vector> t_next(ts + 1, vector(alphabet_size, ts)); for (int i = ts - 1; i >= 0; --i) { for (int j = 0; j < alphabet_size; ++j) { t_next[i][j] = t_next[i + 1][j]; } t_next[i][t[i] - 'a'] = i; } vector back_substr(ss + 1, ts); int k = ts; for (int i = ss - 1; i >= 0; --i) { while (k > 0) { --k; if (s[i] == t[k]) { back_substr[i] = k; break; } } if (back_substr[i] == ts) back_substr[i] = -1; } if (back_substr[0] != -1) { cout << -1 << endl; return 0; } string ans; int s_cnt = 0, t_cnt = 0; bool ended = false; while (!ended) { for (int i = 0; i < alphabet_size; ++i) { if (s_next[s_cnt][i] == ss) { continue; } else if (t_next[t_cnt][i] == ts) { ans.push_back('a' + i); ended = true; break; } else { if (back_substr[s_next[s_cnt][i] + 1] < t_next[t_cnt][i] + 1) { s_cnt = s_next[s_cnt][i] + 1; t_cnt = t_next[t_cnt][i] + 1; ans.push_back('a' + i); break; } } } } cout << ans << endl; return 0; }