#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string a, b;
cin >> a >> b;
list<char> a1, a2, b1, b2;
int n = a.size();
if(a.size() != b.size())
return cout << "-1\n", 0;
for(int i = 0; i < n; i ++)
a2.push_back(a[i]), b1.push_back(b[i]);
for(int i = 0; i < n; i ++){
a1.push_back(a[i]);
a2.pop_front();
b1.pop_back();
b2.push_front(b[n - i - 1]);
string A, B;
for(char x : b2)
A.push_back(x);
for(char x : a2)
A.push_back(x);
for(char x : b1)
B.push_back(x);
for(char x : a1)
B.push_back(x);
if(A == B)
return cout << A << '\n', 0;
}
cout << "-1\n";
}
Copy