#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int ans = 0, speed = 0;
  vector<int> maxspeed, ob;
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int neu;
      cin >> neu;
      speed = neu;
      while (maxspeed.size() > 0 && speed > maxspeed[maxspeed.size() - 1]) {
        ans++;
        maxspeed.pop_back();
      }
    }
    if (t == 2) {
      ans += ob.size();
      ob.clear();
    }
    if (t == 3) {
      int neu;
      cin >> neu;
      maxspeed.push_back(neu);
      while (maxspeed.size() > 0 && speed > maxspeed[maxspeed.size() - 1]) {
        ans++;
        maxspeed.pop_back();
      }
    }
    if (t == 4) {
      ob.clear();
    }
    if (t == 5) {
      maxspeed.clear();
    }
    if (t == 6) {
      ob.push_back(0);
    }
  }
  cout << ans << "\n";
  return 0;
}
