# include<bits/stdc++.h>
using namespace std;
void postorder(string preorder, string inorder)
{
int len = preorder.length();
if(len == 0) return;
if(len == 1)
{
cout<<preorder[0];
return;
}
int pos = inorder.find(preorder[0]);
postorder(preorder.substr(1,pos),inorder.substr(0,pos));
postorder(preorder.substr(1+pos,len-pos-1),inorder.substr(1+pos,len-pos-1));
cout<<preorder[0];
}
int main()
{
string s1, s2;
cin>>s1>>s2;
postorder(s1,s2);
}