//实在不想写数组法了,写个常用的STL的吧
#include "iostream"
#include "algorithm"
#include "stack"
using namespace std;
void Init(stack <int> s)
{
while(!s.empty())
{
s.pop();
}
}
int main()
{
stack <int> s;
int n,q;
while(cin>>n>>q)
{
Init(s);//初始化
for(int i=0;i<n;i++)
{
int key;
cin>>key;
s.push(key);
}
while(q--)
{
int x;
cin>>x;
if(x==1)//出栈
{
if(!s.empty())
s.pop();
}
else if(x==2)//显示栈顶
{
if(!s.empty())
cout<<s.top()<<endl;
}
if(x==3) //进栈
{
int key;
cin>>key;
s.push(key);
}
}
}
}