#include<bits/stdc++.h>
#define ld long double
#define int long long
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
using namespace std;
void solve(){
string s,t;
cin>>s>>t;
map<char,int>mp;
int n=s.length(),m=t.length();
for (int i=1;i<n;i++) {
if (mp.find(s[i])==mp.end())
mp[s[i]]=i;
}
string ans="";
for(int i=m-1;i>=0;i--) {
if (mp.find(t[i])!=mp.end()) {
string x="";
x+=s.substr(0,mp[t[i]]);
x+=t.substr(i,m);
if (x.size()>=3&&x.size()<ans.size()) {
ans=x;
}else if (ans.empty()&&x.size()>=3) {
ans+=x;
}
}
}
if (ans.empty())
cout<<-1<<"\n";
else
cout<<ans<<"\n";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
//cin>>t;
while(t--){
solve();
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsZCBsb25nIGRvdWJsZQojZGVmaW5lIGludCBsb25nIGxvbmcKI2RlZmluZSBhbGwodikgdi5iZWdpbigpLHYuZW5kKCkKI2RlZmluZSBhbGxyKHYpIHYucmJlZ2luKCksdi5yZW5kKCkKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdm9pZCBzb2x2ZSgpewogICAgIHN0cmluZyBzLHQ7CiAgICAgIGNpbj4+cz4+dDsKICAgIG1hcDxjaGFyLGludD5tcDsKICAgIGludCBuPXMubGVuZ3RoKCksbT10Lmxlbmd0aCgpOwogICAgZm9yIChpbnQgaT0xO2k8bjtpKyspIHsKICAgICAgICBpZiAobXAuZmluZChzW2ldKT09bXAuZW5kKCkpCiAgICAgICAgICAgIG1wW3NbaV1dPWk7CiAgICB9CnN0cmluZyBhbnM9IiI7CiAgICBmb3IoaW50IGk9bS0xO2k+PTA7aS0tKSB7CiAgICAgICAgIGlmIChtcC5maW5kKHRbaV0pIT1tcC5lbmQoKSkgewogICAgICAgICAgICAgc3RyaW5nIHg9IiI7CiAgICAgICAgICAgICB4Kz1zLnN1YnN0cigwLG1wW3RbaV1dKTsKICAgICAgICAgICAgICAgIHgrPXQuc3Vic3RyKGksbSk7CgogICAgICAgICAgICAgaWYgKHguc2l6ZSgpPj0zJiZ4LnNpemUoKTxhbnMuc2l6ZSgpKSB7CiAgICAgICAgICAgICAgICAgIGFucz14OwogICAgICAgICAgICAgfWVsc2UgaWYgKGFucy5lbXB0eSgpJiZ4LnNpemUoKT49MykgewogICAgICAgICAgICAgICAgIGFucys9eDsKICAgICAgICAgICAgIH0KICAgICAgICAgfQogICAgfQogICAgaWYgKGFucy5lbXB0eSgpKQogICAgICAgIGNvdXQ8PC0xPDwiXG4iOwogICAgZWxzZQogICAgICAgIGNvdXQ8PGFuczw8IlxuIjsKCgoKfQppbnQzMl90IG1haW4oKSB7CiBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKIGNpbi50aWUobnVsbHB0cik7CiBjb3V0LnRpZShudWxscHRyKTsKIGludCB0PTE7Ci8vY2luPj50Owp3aGlsZSh0LS0pewpzb2x2ZSgpOwp9Cn0=