#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    int n;
    cin >> n;
    string temp;
    int num = 0;
    int x;
    int counts[100001];
    for (int i = 0; i < n; i++) {
        cin >> temp;
        if (temp == "push") {
            cin >> x;
            counts[num] = x;
            num++;
        } else {
            if (num > 0) {
                if (temp == "pop") {
                    cout << counts[num - 1] << endl;
                    num--;
                } else {
                    cout << counts[num - 1] << endl;
                }
            } else {
                cout << "error" << endl;
            }
        }
    }
}
// 64 位输出请用 printf("%lld")