#include<cstdio>
#include<cstdlib>
#include<stack>
#include<vector>
using namespace std;
struct node{
int key;
node* lchild;
node* rchild;
};
vector<int> v;
void postOrder(node* root)
{
if(root==NULL) return;
postOrder(root->lchild);
postOrder(root->rchild);
v.push_back(root->key);
}
int main()
{
int N,key;
scanf("%d",&N);
getchar();
stack<node*> st;
char str[5];
node* root = NULL;
node* realRoot = NULL;
while(scanf("%s",str)!=EOF){
if(str[1]=='u'){
scanf("%d",&key); getchar();
node* tmp = (node*)malloc(sizeof(struct node));
tmp->key = key;
tmp->lchild = tmp->rchild = NULL;
if(root==NULL){
root = tmp;
realRoot = root;
}
else if(root->lchild==NULL){
root->lchild = tmp;
root = tmp;
}
else{
root->rchild = tmp;
root = tmp;
}
st.push(tmp);
}
else{
getchar();
root = st.top(); st.pop();
}
}
postOrder(realRoot);
for(int i=0; i<v.size(); i++){
if(i!=v.size()-1){
printf("%d ",v[i]);
}
else{
printf("%d\n",v[i]);
}
}
return 0;
}