#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 20;
const int inf = 1e9;
vector<pair<int, int> > scline[maxn];
map<int, int> m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int curv = 0;
  vector<int> maxv;
  maxv.push_back(inf);
  int obgon = 0;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int t, v;
    cin >> t;
    if (t == 1) {
      cin >> v;
      curv = v;
      if (maxv.back() < v) {
        while (maxv.back() < v) {
          maxv.pop_back();
          cnt++;
        }
      }
    }
    if (t == 2) {
      if (obgon) {
        cnt += obgon;
        obgon = 0;
      }
    }
    if (t == 3) {
      cin >> v;
      if (curv <= v)
        maxv.push_back(v);
      else
        cnt++;
    }
    if (t == 4) {
      obgon = 0;
    }
    if (t == 5) {
      maxv.resize(0);
      maxv.push_back(inf);
    }
    if (t == 6) {
      obgon++;
    }
  }
  cout << cnt << endl;
}
