#include <bits/stdc++.h>
using namespace std;
int main() {
  int limit = INT_MAX;
  int speed;
  int ans = 0;
  int count = 0;
  int isNotLLOWED = 0;
  int isvio = 0;
  int n;
  cin >> n;
  stack<int> s;
  for (int i = 0; i < n; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      cin >> speed;
      while (!s.empty() && speed > s.top()) {
        ans++;
        s.pop();
      }
    } else if (type == 2) {
      if (isNotLLOWED) {
        ans += count;
        count = 0;
      }
    } else if (type == 3) {
      cin >> limit;
      if (speed > limit) {
        ans++;
      } else {
        s.push(limit);
      }
    } else if (type == 4) {
      isNotLLOWED = 0;
      count = 0;
    } else if (type == 5) {
      while (!s.empty()) s.pop();
    } else if (type == 6) {
      isNotLLOWED = 1;
      count++;
    }
  }
  cout << ans << "\n";
  return 0;
}
