#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int i;
  int tem;
  int speed_sig = 0;
  int overtake_sig = 0;
  int num = 0;
  int speed_limit = -1;
  int speed;
  int overtake_num = 0;
  int speed_num = 0;
  vector<int> speedLimits;
  int top = 0;
  speedLimits.push_back(1000);
  cin >> n;
  vector<int> a, b;
  for (i = 0; i < n; i++) {
    cin >> tem;
    a.push_back(tem);
    if (tem == 1 || tem == 3) {
      cin >> tem;
      b.push_back(tem);
    } else
      b.push_back(-1);
    switch (a[i]) {
      case 1:
        speed = b[i];
        if (speed_sig == 0)
          break;
        else {
          if (speed_limit >= b[i])
            break;
          else {
            while (top >= 0 && speedLimits[top] < speed) {
              num++;
              speedLimits.pop_back();
              top--;
            }
            speed_sig = speedLimits[top] == 1000 ? 0 : 1;
            speed_limit = speedLimits[top];
            break;
          }
        }
      case 2:
        if (overtake_sig == 0)
          break;
        else {
          num += overtake_num;
          overtake_num = 0;
          overtake_sig = 0;
          break;
        }
      case 3:
        speed_sig = 1;
        speed_limit = b[i];
        if (speed_limit >= speed) {
          speedLimits.push_back(speed_limit);
          top++;
          break;
        } else {
          num++;
          speed_limit = speedLimits[top];
          speed_sig = speed_limit == 1000 ? 0 : 1;
          break;
        }
      case 4:
        overtake_sig = 0;
        overtake_num = 0;
        break;
      case 5:
        speed_sig = 0;
        speed_limit = 1000;
        speedLimits.push_back(1000);
        top++;
        break;
      case 6:
        overtake_sig = 1;
        overtake_num++;
        break;
      default:
        break;
    }
  }
  cout << num << endl;
  return 0;
}
