#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int min = 0;
  int overtake = 0;
  stack<int> pq;
  int velocity = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      cin >> velocity;
    }
    if (x == 2) {
      min += overtake;
      overtake = 0;
    }
    if (x == 3) {
      int lim;
      cin >> lim;
      pq.push(lim);
    }
    if (x == 4) {
      overtake = 0;
    }
    if (x == 5) {
      while (!pq.empty()) {
        pq.pop();
      }
    }
    if (x == 6) {
      overtake++;
    }
    if (!pq.empty()) {
      while (!pq.empty() && velocity > pq.top()) {
        pq.pop();
        min++;
      }
    }
  }
  cout << min << endl;
  return 0;
}
