#include <bits/stdc++.h>
using namespace std;
void solve() {
  int tt;
  cin >> tt;
  vector<int> speedLimit;
  int ans = 0;
  int cnt = 0;
  int speed;
  int noOvertake = 0;
  while (tt--) {
    int type;
    cin >> type;
    if (type == 1) {
      int x;
      cin >> x;
      speed = x;
    }
    if (type == 2) {
      ans += noOvertake;
      noOvertake = 0;
    }
    if (type == 3) {
      int speedL;
      cin >> speedL;
      speedLimit.push_back(speedL);
    }
    if (type == 4) {
      noOvertake = 0;
    }
    if (type == 5) {
      speedLimit.clear();
    }
    if (type == 6) {
      noOvertake++;
    }
    while (speedLimit.size() > 0 && speed > speedLimit.back()) {
      ans++;
      speedLimit.pop_back();
    }
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
}
