#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, ans, s, f, now;
vector<int> speedLimit, canOvertake;
int main() {
  scanf("%d", &n);
  speedLimit.push_back(300);
  canOvertake.push_back(1);
  while (n--) {
    scanf("%d", &f);
    if (f == 1) {
      scanf("%d", &s);
      now = s;
      if (s <= speedLimit.back()) continue;
      while (s > speedLimit.back()) speedLimit.pop_back(), ans++;
    }
    if (f == 2) {
      if (canOvertake.back()) continue;
      while (canOvertake.back() == 0) canOvertake.pop_back(), ans++;
    }
    if (f == 3) {
      scanf("%d", &s);
      speedLimit.push_back(s);
      if (now <= s) continue;
      while (now > speedLimit.back()) speedLimit.pop_back(), ans++;
    }
    if (f == 4) {
      canOvertake.push_back(1);
    }
    if (f == 5) {
      speedLimit.push_back(300);
    }
    if (f == 6) {
      canOvertake.push_back(0);
    }
  }
  printf("%d\n", ans);
}
