#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; using ull = unsigned long long; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; } mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353; constexpr int MAX = 1100000; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s >> t; auto nextcharchter = [](string s)->vector> { int n = s.size(); vector> ret(n + 1, vector(26, n)); for (int i = n - 1; i >= 0; i--) { if (i + 1 < n) { for (int j = 0; j < 26; j++) { ret[i][j] = ret[i + 1][j]; } } ret[i][s[i] - 'a'] = i; } return ret; }; auto ns = nextcharchter(s); auto nt = nextcharchter(t); vector lst(s.size()); { int cur = (int)t.size() - 1; for (int i = (int)s.size() - 1; i >= 0; i--) { while (cur >= 0 and t[cur] != s[i]) cur--; lst[i] = cur; if (cur >= 0) cur--; } } if (lst[0] != -1) { cout << -1 << endl; return 0; } string res; int sc = 0; int tc = 0; while (true) { for (int i = 0; i < 26; i++) { if (ns[sc][i] == s.size()) continue; if (nt[tc][i] == t.size()) { res += (char)(i + 'a'); cout << res << "\n"; exit(0); } if (lst[ns[sc][i]] >= nt[tc][i]) continue; res += (char)(i + 'a'); sc = ns[sc][i] + 1; tc = nt[tc][i] + 1; break; } } }