#include<bits/stdc++.h>
using namespace std;
class tree
{
	public:
	int data;
	tree*left;
	tree*right;
	tree(int d)
	{
		data=d;
		left=NULL;
		right=NULL;
	}
};
tree*build()
{
	int d;
	cin>>d;
	if(d==-1) return NULL;
	tree*root=new tree(d);
	root->left=build();
	root->right=build();
	return root;
}
void verticalorderprint(tree*root,int dist,map<int,int>&m)
{
  if(root->left==0 && root->right==0)
  return;
    
    m[dist]=root->data;
    
    verticalorderprint(root->left,dist+=-1,m);
    verticalorderprint(root->right,dist+=1,m);
}
int main()
{
  tree*root=build();
    map<int,int> m;
    verticalorderprint(root,0,m);
    for(auto it=m.begin();it!=m.end();it++) cout<<it->second<<" ";
    
    return 0;
}