#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
int a[N], b[N], p[N];
int main() {
  scanf("%d", &n);
  int ans = 0;
  int last = 0, speed = 0, last_overtake = 0, overtake = 1;
  b[0] = 300;
  a[0] = 4;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] == 1 || a[i] == 3) scanf("%d", &b[i]);
    if (a[i] == 5) b[i] = 300;
    if (a[i] == 3 || a[i] == 5) p[i] = last, last = i;
    if (a[i] == 4 || a[i] == 6) p[i] = last_overtake, last_overtake = i;
    if (a[i] == 1) speed = b[i];
    while (speed > b[last]) {
      ++ans;
      last = p[last];
    }
    if (a[i] == 2) {
      while (a[last_overtake] == 6) {
        ++ans;
        last_overtake = p[last_overtake];
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
