#include<bits/stdc++.h>
using namespace std;
const int N =100000;
int lson[N],rson[N];char in[N],po[N],ans[N];
int cnt = 1;
void dfs(int u,int m1,int m2,int s1,int s2)
{
ans[m2] = po[s1];
int t=0;
for(int i=m1;i<=m2;++i)
{
if(po[i]==ans[m2]) t = i;
}
if(t!=m1)
{
lson[u] = ++cnt;
dfs(lson[u],m1,t-1,s1,s1+(t-m1-1));
}
if(t!=m2)
{
rson[u] = ++cnt;
dfs(rson[u],t+1,m2,s1+t-m1,s2-1);
}
}
void print(int u)
{
cout<<ans[u];
if(lson[u]) print(lson[u]);
if(rson[u]) print(rson[u]);
}
int main()
{
cin>>po>>in;
int sl = strlen(in);
dfs(1,0,sl-1,0,sl-1);
print(1);
return 0;
}