#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265
#define fast ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef pair<ll,ll> pli;
typedef pair<int,int> pii;
typedef pair<ld,ld> pld;
ll MOD=1000000007 ;
ll MX=1000000000000000;
char a[5050];
char b[5050];
int main()
{
fast;
//freopen("input.txt","r",stdin);
cin>>(a+1);
cin>>(b+1);
ll n=strlen(a+1);
ll m=strlen(b+1);
if((n+m)%2==1)
{
cout<<"-1\n";
}
else
{
string res="";
string pref="";
string suff="";
ll stx=-1,sty=-1;
if(n<=m)
{
stx=0;
sty=(m-n)/2;
}
else
{
stx=(n-m)/2;
sty=0;
}
for(int i=1;i<=stx;i++)
pref+=a[i];
for(int j=m;j>m-sty;j--)
{
suff=b[j]+suff;
}
for(int i=0;i<=n;i++)
{
ll x=i+stx;
ll y=sty+i;
if(x!=0)
pref+=a[x];
if(y>m)
continue;
if(y!=0)
{
suff=b[m-y+1]+suff;
}
string a1=suff;
for(int j=x+1;j<=n;j++)
a1+=a[j];
string b1="";
for(int j=1;j<=m-y;j++)
b1+=b[j];
b1+=pref;
ll temp=1;
for(int j=0;j<a1.size();j++)
{
if(a1[j]!=b1[j])
temp=0;
}
if(temp)
{
res=a1;
break;
}
}
if(res=="")
{
cout<<"-1\n";
}
else
{
cout<<res<<endl;
}
}
return 0;
}
Copy