#include <bits/stdc++.h>
using namespace std;
int main()
{
stack<int> a;
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
string ct;
int x;
cin >> ct;
if(ct == "push")
{
cin >> x;
a.push(x);
}
else if(ct == "pop")
{
if(!a.empty())
{
a.pop();
}
}
}
while(!a.empty())
{
cout << a.top() << " ";
a.pop();
}
return 0;
}