#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
const int N=2e5+5;
ll Q,tot=0,s[N],a[N];
multiset<ll> st;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int c;
cin>>c>>Q;
ll k=0;
int id=1;
while(Q--){
int op,x;
cin>>op;
if(op==1){
cin>>x;
s[++tot]=s[tot-1]+x;
st.insert(x);
a[tot]=x;
}
if(op==2){
cin>>x;
k+=x;
while(s[id]<=k&&id<=tot){
st.erase(st.find(a[id]));
++id;
}
}
if(op==3){
cin>>x;
x+=k;
int p=lower_bound(s+1,s+tot+1,x)-s-1;
cout<<x-s[p]<<'\n';
}
if(op==4){
cout<<*st.rbegin()<<'\n';
}
}
return 0;
}