#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
int n, speed, maxSpeed = 310, ans, cnt;
bool overtake, allow = true;
vector<int> markSpeed;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x;
    if (x == 1) {
      cin >> y;
      speed = y;
      while (markSpeed.size()) {
        if (markSpeed[markSpeed.size() - 1] < speed) {
          markSpeed.pop_back();
          ans++;
        } else {
          break;
        }
      }
    }
    if (x == 2) {
      if (allow == false) {
        if (cnt) {
          ans += cnt;
          cnt = 0;
        }
      }
    }
    if (x == 3) {
      cin >> y;
      maxSpeed = y;
      if (speed > y)
        ans++;
      else
        markSpeed.push_back(y);
    }
    if (x == 4) {
      allow = true;
      cnt = 0;
    }
    if (x == 5) {
      maxSpeed = 310;
      markSpeed.clear();
    }
    if (x == 6) {
      allow = false;
      cnt++;
    }
  }
  cout << ans << endl;
}
