#include <iostream> 
using namespace std; 
 
class Stack{ 
    private: 
        int arr[1000]; 
        int top; 
    public: 
        Stack(){top=-1;} 
        void push(int x){ 
            top++; 
            arr[top] =x; 
 
        } 
        int pop(){ 
            if(top>=0){ 
                int x= arr[top]; 
                top--; 
                return x; 
            } 
            else{ 
                return -1; 
            } 
        } 
}; 
 
int main(){ 
    int test; 
    cin>>test; 
     
    while(test--){ 
        int action, value; 
        cin>>action>>value; 
        Stack Mystack; 
        if(action==1){ 
            Mystack.push(value); 
        } 
        if(action ==2){ 
            int y = Mystack.pop(); 
            cout<<y<<endl; 
    } 
    } 
     
 
}