#include using namespace std; int INF = 1000000; int main(){ string S; cin >> S; string T; cin >> T; int N = S.size(); int M = T.size(); vector p(N + 1, -1); p[N] = M; int ps = M - 1; for (int i = N - 1; i >= 0; i--){ if (i < N - 1){ ps--; } if (ps != -1){ while (T[ps] != S[i]){ ps--; if (ps == -1){ break; } } } if (ps == -1){ break; } else { p[i] = ps; } } if (p[0] != -1){ cout << -1 << endl; } else { vector> next1(N + 1, vector(26, N)); for (int i = N - 1; i >= 0; i--){ next1[i] = next1[i + 1]; next1[i][S[i] - 'a'] = i; } vector> next2(M + 1, vector(26, M)); for (int i = M - 1; i >= 0; i--){ next2[i] = next2[i + 1]; next2[i][T[i] - 'a'] = i; } string ans = ""; int p1 = 0, p2 = 0; while (1){ bool ok = false; bool ok2 = false; for (int i = 0; i < 26; i++){ if (next1[p1][i] != N){ if (next2[p2][i] == M){ ans += 'a' + i; ok = true; break; } else { int p3 = next1[p1][i] + 1; int p4 = next2[p2][i] + 1; if (p[p3] < p4){ ans += 'a' + i; p1 = p3; p2 = p4; ok2 = true; break; } } } } if (ok || !ok2 || p1 == N){ break; } } cout << ans << endl; } }