#include <bits/stdc++.h>
using namespace std;
stack<int> speedLimits;
int main() {
  int n, type, q, speed, speedLimit, ignored = 0, no = 0;
  bool canOvertake = true, limitIgnore = true;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &speed);
      while (!speedLimits.empty() && ((speedLimits.top()) < speed))
        ignored++, speedLimits.pop();
    } else if (type == 2) {
      ignored += no;
      no = 0;
    } else if (type == 3) {
      scanf("%d", &speedLimit);
      speedLimits.push(speedLimit);
      while (!speedLimits.empty() && ((speedLimits.top()) < speed))
        ignored++, speedLimits.pop();
    } else if (type == 4)
      canOvertake = true, no = 0;
    else if (type == 5)
      speedLimits = stack<int>();
    else if (type == 6)
      canOvertake = false, no++;
  }
  printf("%d\n", ignored);
  return 0;
}
