#include <bits/stdc++.h>
using namespace std;
int aa[200005];
int main() {
  int n, j, a, v, v0, v1, vk, flag1, flag2, chaoshu, ans;
  while (scanf("%d", &n) != EOF) {
    ans = 0;
    v0 = 300;
    flag1 = flag2 = 0;
    chaoshu = 0;
    j = 1;
    aa[1] = 400;
    while (n--) {
      scanf("%d", &a);
      if (a == 1) {
        scanf("%d", &v1);
        while (aa[j] < v1) {
          j--, ans++;
        }
      } else if (a == 2) {
        ans += chaoshu;
        chaoshu = 0;
      } else if (a == 3) {
        scanf("%d", &v0);
        if (v1 > v0) {
          ans = ans + 1;
        } else
          aa[++j] = v0;
      } else if (a == 4) {
        flag2 = 0;
        chaoshu = 0;
      } else if (a == 5) {
        v0 = 300;
        j = 1;
      } else if (a == 6) {
        flag2 = 1;
        chaoshu++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
