#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define TEST int t;cin>>t;while(t--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fr first
#define sc second
#define popcount __builtin_popcountll
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const ll mod=1000000007;
typedef vector<int,int> p1;
typedef vector<ll,ll> p2;
int main()
{
IOS;
//TEST{
string a,b,res="-1";
cin>>a>>b;
vector<string>str,sb,st,sbb;
str.pb(a);
sb.push_back(b);
st.pb(a);
sbb.pb(b);
rep(i,a.length()){
string str1=a.substr(0,i+1);
string sss=a.substr(a.length()-i-1,a.length());
// cout<<str1<<" "<<sss<<endl;
if(str1!=sss||str1==a)continue;
str.pb(str1);
string str2=a.substr(i+1,a.length());
st.pb(str2);
}
rep(i,b.length()){
string sb1=b.substr(b.length()-i-1,b.length());
string sss=b.substr(0,i+1);
if(sb1!=sss||sb1==b)continue;
sb.pb(sb1);
string sb2=b.substr(0,b.length()-i-1);
sbb.pb(sb2);
}
bool l=0;
rep(i,str.size()){
if(l)break;
for(int j=0;j<sb.size();j++){
if(string(sb[j]+st[i])==string(sbb[j]+str[i])){res=sbb[j]+str[i]; l=1;}
}
}
/*
rep(i,st.size())cout<<st[i]<<" ";
cout<<endl;
rep(i,sb.size())cout<<sb[i]<<" ";
cout<<endl;
*/
if(a==b)res=a;
cout<<res;
cout<<endl;
//}
return 0;
}
Copy