#include<iostream>
#include<vector>
using namespace std;
struct node{
int value;
node* left;
node* right;
};
vector<int> pre,in,pos;
node* build(int prel,int prer,int inl,int inr){
if(prel>prer) return 0;
node* root=new node;
root->value=pre[prel];
root->left=NULL;
root->right=NULL;
int k;
for(k=inl;k<=inr;k++){
if(pre[prel]==in[k]){
break;
}
}
int numleft=k-inl;//左子树节点个数
root->left=build(prel+1,prel+numleft,inl,k-1);
root->right=build(prel+numleft+1,prer,k+1,inr);
return root;
}
void post(node* root){
if(root==NULL) return;
post(root->left);
post(root->right);
pos.push_back(root->value);
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
#endif
int n;
cin>>n;
for(int i=0;i<n;i++){
int temp;
cin>>temp;
pre.push_back(temp);
}
for(int i=0;i<n;i++){
int temp;
cin>>temp;
in.push_back(temp);
}
node* root=build(0,n-1,0,n-1);;
post(root);
//for(int i=0;i<n;i++)
cout<<pos[0]<<endl;
return 0;
}