#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 11234;
enum Cmd {
  SpeedChanged = 1,
  Overtake = 2,
  SpeedLimit = 3,
  AllowOvertake = 4,
  NoSpeedLimit = 5,
  DisallowOvertake = 6,
};
int main(void) {
  int n;
  cin >> n;
  int speed = 0;
  vector<int> limits;
  int disallowOvertake = 0;
  int cnt = 0, limit;
  for (int i = 0; i < (n); i++) {
    int cmd;
    cin >> cmd;
    switch (cmd) {
      case SpeedChanged:
        cin >> speed;
        while (!limits.empty() && speed > limits.back()) {
          cnt++;
          limits.pop_back();
        }
        break;
      case Overtake:
        if (disallowOvertake != 0)
          cnt += disallowOvertake, disallowOvertake = 0;
        break;
      case SpeedLimit:
        cin >> limit;
        if (speed > limit)
          cnt++;
        else {
          limits.push_back(limit);
        }
        break;
      case AllowOvertake:
        disallowOvertake = 0;
        break;
      case NoSpeedLimit:
        limits.clear();
        break;
      case DisallowOvertake:
        disallowOvertake++;
        break;
    }
  }
  cout << cnt << endl;
}
