#include <bits/stdc++.h>
using namespace std;
const int INF = 301;
int main() {
  int n;
  cin >> n;
  int vmax = INF;
  vector<int> speed;
  speed.push_back(INF);
  vector<bool> overtake;
  overtake.push_back(true);
  int curv = 0;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      cin >> curv;
      while (curv > speed.back()) {
        speed.pop_back();
        cnt++;
      }
    }
    if (t == 2) {
      while (!overtake.back()) {
        overtake.pop_back();
        cnt++;
      }
    }
    if (t == 3) {
      int vi;
      cin >> vi;
      speed.push_back(vi);
      while (curv > speed.back()) {
        speed.pop_back();
        cnt++;
      }
    }
    if (t == 4) {
      overtake.push_back(true);
    }
    if (t == 5) {
      speed.push_back(INF);
    }
    if (t == 6) {
      overtake.push_back(false);
    }
  }
  cout << cnt << "\n";
  return 0;
}
