import java.util.*;
public class Main{
public static void main(String[] arg){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String[] strs = sc.nextLine().split(" ");
int N = Integer.parseInt(strs[0]);
int[] arr = new int[N*2];
for(int i= 1;i<N*2;i++){
arr[i] = Integer.parseInt(strs[i]);
}
int del = Integer.parseInt(strs[2*N]);
Node tou = new Node(arr[1]);
for(int i= 2;i<N*2;i=i+2){
zhao(tou,arr[i],arr[i+1]);
}
// Node head = tou;
// while(head!=null){
// System.out.print(head.val+" ");
// head=head.next;
// }
//删除
shan(tou,del);
Node head = tou;
while(head!=null){
System.out.print(head.val+" ");
head=head.next;
}
}
}
public static void zhao(Node tou,int x,int y){
Node head = tou;
while(head!=null){
if(head.val==y){
Node tem = new Node(x);
Node hou = head.next;
head.next = tem;
tem.next = hou;
break;
}else{
head=head.next;
}
}
}
public static Node shan(Node tou,int val){
Node head = tou;
if(head==null){
return null;
}
if(head.next==null){
if(head.val!=val){
return null;
}else{
return null;
}
}
if(head.val==val){
tou=head.next;
return tou;
}
while(head.next!=null){
if(head.next.val==val){
head.next = head.next.next;
break;
}else{
head=head.next;
}
}
return tou;
}
}
class Node{
int val;
Node next;
public Node(int val){
this.val = val;
}
}