#include <bits/stdc++.h>
using namespace std;
int p[222222];
int n, ms, s, a, f, ot, z, st;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  f = 0;
  p[0] = 1e9;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 1) {
      cin >> s;
      while (s > p[st]) {
        ot++;
        st--;
      }
    }
    if (a == 2)
      if (f == 1) {
        ot += z;
        z = 0;
      }
    if (a == 3) {
      cin >> ms;
      if (ms < s)
        ot++;
      else {
        st++;
        p[st] = ms;
      }
    }
    if (a == 4) {
      f = 0;
      z = 0;
    }
    if (a == 5) st = 0;
    if (a == 6) {
      z++;
      f = 1;
    }
  }
  cout << ot << endl;
}
