#include <bits/stdc++.h>
using namespace std;
int main() {
int n,t,s,sl=-1,ot=1,ans=0,cs=-1,usot=0;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d",&t);
switch(t)
{
case(1): scanf("%d",&s);
cs=s;
if(sl!=-1&&s>sl) ans++;
break;
case(2): if(!ot) ans+=usot; usot=0;
break;
case(3): scanf("%d",&s);
if(cs>s) ans++;
sl=s;
break;
case(4): ot=1; usot=0; break;
case(5): sl=-1; break;
case(6): usot++;ot=0; break;
}
}
printf("%d",ans);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICAgaW50IG4sdCxzLHNsPS0xLG90PTEsYW5zPTAsY3M9LTEsdXNvdD0wOwogICBzY2FuZigiJWQiLCZuKTsKICAgZm9yKGludCBpPTA7IGk8bjsgaSsrKQogICB7CiAgIAlzY2FuZigiJWQiLCZ0KTsKICAgCXN3aXRjaCh0KQogICAJewogICAJCWNhc2UoMSk6IHNjYW5mKCIlZCIsJnMpOwogICAJCQkJIGNzPXM7CiAgIAkJCQkgaWYoc2whPS0xJiZzPnNsKSBhbnMrKzsKICAgCQkJCSBicmVhazsKICAgCQljYXNlKDIpOiBpZighb3QpIGFucys9dXNvdDsgdXNvdD0wOwogICAJCQkJIGJyZWFrOwogICAJCWNhc2UoMyk6IHNjYW5mKCIlZCIsJnMpOwogICAJCQkJIGlmKGNzPnMpIGFucysrOwogICAJCQkJIHNsPXM7CiAgIAkJCQkgYnJlYWs7CiAgIAkJY2FzZSg0KTogb3Q9MTsgdXNvdD0wOyBicmVhazsKICAgCQljYXNlKDUpOiBzbD0tMTsgYnJlYWs7CiAgIAkJY2FzZSg2KTogdXNvdCsrO290PTA7IGJyZWFrOwogICAJfQogICB9CiAgIHByaW50ZigiJWQiLGFucyk7Cn0=