#include using namespace std; #define modulo 998244353 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000005 int main(){ string S,T; cin>>S>>T; vector> nS(S.size()+1),nT(T.size()+1); { vector now(26,Inf); for(int i=S.size();i>=0;i--){ nS[i] = now; if(i!=0){ now[S[i-1]-'a']=i; } } } { vector now(26,Inf); for(int i=T.size();i>=0;i--){ nT[i] = now; if(i!=0){ now[T[i-1]-'a']=i; } } } vector ind(T.size(),Inf); int pos = S.size(); for(int i=T.size()-1;i>=0;i--){ if(pos!=0&&T[i]==S[pos-1]){ pos--; } ind[i] = pos; } string ans = ""; int posS = 0,posT = 0; while(true){ bool f = false; for(int i=0;i<26;i++){ if(nS[posS][i]==Inf)continue; if(nT[posT][i]==Inf){ ans += 'a'+i; goto L; } int s = nS[posS][i]-1; int t = nT[posT][i]-1; if(ind[t]<=s)continue; posS = s+1; posT = t+1; ans += 'a'+i; f=true; break; } if(!f)break; } L:; if(ans==""){ cout<<-1<