#include 
using namespace std;
class node{
public:
int data;
nodeleft;
noderight;
  node(int d){
      int data=d;
      node*left=NULL;
      node*right=NULL;
  }
};
node* insertinBST(node*root,int data){
//base case
if(root==NULL){
return new node(data);
}
//rec case 
if(data<=root->data){
    root->left=insertinBST(root->left,data);
}
else{
    root->right=insertinBST(root->right,data);
}
return root;
}
node* buildBST(){
int data;
cin>>data;
node*root=NULL;
while(data!=-1){
    root=insertinBST(root,data);
    cin>>data;
}
return root;
}
void printpreorder(node*root){
if(root==NULL){
return;
}
cout<<root->data<<" ";
printpreorder(root->left);
printpreorder(root->right);
}
int main() {
node*root=buildBST();
printpreorder(root);
cout<<endl;
//  printlevelorder(root);
}
      
    