#include <bits/stdc++.h>
using namespace std;

class Node{
    public:
        int data;
        Node*left;
        Node*right;
    Node(int d){
        data = d;
        left = NULL;
        right = NULL;
    }
};

// this is same as bfs

Node* buildTree(){

queue<Node*>q;

int d;cin>>d;

// if -1 return null

if(d==-1)return NULL;

// else make node and push to queue

Node*head=new Node(d);

q.push(head);

int lc,rc;

// now till the queue is not empty pop and push the children if next input is not -1

while(!q.empty()){

    Node*f=q.front();

    q.pop();

    cin>>lc>>rc;

    if(lc!=-1){

        f->left=new Node(lc);

        q.push(f->left);

    }

    if(rc!=-1){

        f->right=new Node(rc);

        q.push(f->right);

    }

}

// finally return head

return head;
}


void print_left_side(Node*root, int level, int &maxlevel){
    if(root==NULL){
        return;
    }

    if(maxlevel<level){
        cout<<root->data<<" ";
        maxlevel = level;
    }

    print_left_side(root->left, level+1, maxlevel);
    print_left_side(root->right, level+1, maxlevel);
}


int main(){
    Node*root = buildTree();
    int maxLevel = -1;
    int maxLevel2 = -1;
    print_left_side(root,0,maxLevel2);
}