#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; stack<int> s; while(n--){ int k=0; cin>>k; if(k==1){ int m; cin>>m; s.push(m); // 將m輸入推疊 } else if (k==2){ if(s.empty()){ // 如果堆疊為空 cout<<-1<<endl; } else{ cout<<s.top()<<endl; // 輸出堆疊s的頂端 } } else { if(s.empty()){ continue; } else{ s.pop(); // pop出堆疊的頂端 } } } return 0; }