#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<pair<int, int> > a;
  vector<int> b;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    if (t & 1) {
      int spd = 0;
      if (t != 5) scanf("%d", &spd);
      a.push_back({t, spd});
    } else {
      b.push_back(t);
    }
  }
  int res = 0;
  int spd = 0;
  vector<int> lim;
  lim.push_back(1e9);
  for (pair<int, int> p : a) {
    if (p.first == 1) {
      spd = p.second;
      while (spd > lim.back()) {
        lim.pop_back();
        res++;
      }
    }
    if (p.first == 3) {
      if (spd <= p.second)
        lim.push_back(p.second);
      else
        res++;
    }
    if (p.first == 5) lim.push_back(1e9);
  }
  vector<bool> allowed;
  allowed.push_back(1);
  for (int p : b) {
    if (p == 2) {
      while (!allowed.back()) {
        allowed.pop_back();
        res++;
      }
    }
    if (p == 4) allowed.push_back(1);
    if (p == 6) allowed.push_back(0);
  }
  printf("%d\n", res);
  return 0;
}
