#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
const long long big = 1e18;
const long long block = 800;
const long long mod = 1e6;
long long n;
stack<long long> ogr;
long long cnt;
long long spd;
long long ans = 0;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  while (n--) {
    long long q, second;
    cin >> q;
    if (q == 1) {
      cin >> second;
      spd = second;
      while (ogr.size() && ogr.top() < spd) ans++, ogr.pop();
    }
    if (q == 2) {
      ans += cnt;
      cnt = 0;
    }
    if (q == 3) {
      cin >> second;
      ogr.push(second);
      while (ogr.size() && ogr.top() < spd) ans++, ogr.pop();
    }
    if (q == 4) {
      cnt = 0;
    }
    if (q == 5) {
      while (ogr.size()) ogr.pop();
    }
    if (q == 6) {
      cnt++;
    }
  }
  cout << ans;
}
