#include "bits/stdc++.h" using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i) #define ALL(a) a.begin(), a.end() #define IN(a, x, b) (a <= x && x < b) templateistream&operator >>(istream&is,vector&vec){for(T&x:vec)is>>x;return is;} templateinline void out(T t){cout << t << "\n";} templateinline void out(T t,Ts... ts){cout << t << " ";out(ts...);} templateinline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;} templateinline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;} constexpr int INF = 1e18; vector > calcNext(const string &S) { int n = (int)S.size(); vector > res(n+1, vector(26, n)); for (int i = n-1; i >= 0; --i) { for (int j = 0; j < 26; ++j) res[i][j] = res[i+1][j]; res[i][S[i]-'a'] = i; } return res; } vector makeSubString(const string &s, const string &t) { vectorret; int now = 0; for(auto e: s) { while(now < t.size() && e != t[now]) ++now; ++now; ret.emplace_back(now); } return ret; } signed main(){ string s, t; cin >> s >> t; auto nextS = calcNext(s); auto nextT = calcNext(t); reverse(ALL(s)); reverse(ALL(t)); auto dp = makeSubString(s, t); reverse(ALL(s)); reverse(ALL(t)); reverse(ALL(dp)); int Scur = 0, Tcur = 0; string ans; while(Scur < s.size()) { int nextc = -1; REP(d, 26) if(nextS[Scur][d] < s.size()) { if(dp[nextS[Scur][d]] + Tcur > t.size()) { nextc = d; break; } } if(nextc < 0) { out(-1); return 0; } ans += 'a' + nextc; Scur = nextS[Scur][nextc] + 1; Tcur = nextT[Tcur][nextc] + 1; if(Tcur > t.size()) break; } out(ans); }