import java.util.*;
public class Main {
static Scanner scn=new Scanner(System.in);
public class Node{
int data;
Node left;
Node right;
}
private Node root;
public Main(){
this.root=construct();
}
private Node construct(){
int n=scn.nextInt();
if(n==-1){
return null;
}
Node nn=new Node();
nn.data=n;
LinkedList q=new LinkedList<>();
q.addLast(nn);
while(!q.isEmpty()){
Node rn=q.removeFirst();
n=scn.nextInt();
if(n!=-1){
Node lc=new Node();
lc.data=n;
rn.left=lc;
q.addLast(lc);
}
n=scn.nextInt();
if(n!=-1){
Node rc=new Node();
rc.data=n;
rn.right=rc;
q.addLast(rc);
}
}
return nn;
}
public void bottomView() {
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
bottomView(this.root, map, 0);
ArrayList<Integer> list = new ArrayList<Integer>(map.keySet());
Collections.sort(list);
for (int i = 0; i < list.size(); i++) {
System.out.print(map.get(list.get(i))+" ");
}
System.out.println();
}
private void bottomView(Node root, HashMap<Integer, Integer> map, int vl) {
// TODO Auto-generated method stub
if (root == null) {
return;
}
map.put(vl, root.data);
bottomView(root.left, map, vl - 1);
bottomView(root.right, map, vl + 1);
}
public static void main(String args[]) {
Main m=new Main();
m.bottomView();
}
}