#include<cstdio>
#include<deque>
#define int long long
using namespace std;
int top[200002],prv[200002];
signed main(signed argc,char **argv){
int pos,got,num=1,len,sum;
deque<int> queue;
scanf("%lld %lld",&pos,&pos);
while(pos--){
int sym;
scanf("%lld",&sym);
if(sym==1){
scanf("%lld",&got);
top[++len]=got;
prv[len]=prv[len-1]+got;
prv[len+1]=-922337203685477588ll;
while(!queue.empty()){
if(top[queue.back()]<got){
break;
};
queue.pop_back();
};
queue.push_back(len);
}else if(sym==2){
scanf("%lld",&got);
sum+=got;
while(sum>=prv[num]){
num++;
};
while(!queue.empty()&&queue.front()<num){
if(queue.front()>=num){
break;
};
queue.pop_front();
};
}else if(sym==3){
scanf("%lld",&got);
int low=num-1,hih=len;
while(low+1<hih){
int mid=(low+hih)/2;
if(prv[mid]-sum>=got){
hih=mid;
}else{
low=mid;
};
};
printf("%lld\n",got-prv[hih-1]+sum);
}else{
printf("%lld\n",top[queue.front()]);
};
};
return 0;
};