#include <bits/stdc++.h>
#pragma G++ optimize(2)
using namespace std;
const int M = 200005;
int n, ans, q[M][2], r, s, st, over;
int main() {
  scanf("%d", &n);
  for (int i = 1, op; i <= n; i++) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d", &s);
      while (r > 0 && q[r][0] < s) {
        ans += q[r][1];
        r--;
      }
    }
    if (op == 2) {
      ans += over;
      over = 0;
    }
    if (op == 3) {
      scanf("%d", &st);
      if (st < s) {
        ans++;
        continue;
      }
      if (r > 0 && q[r][0] <= st) {
        q[r][0] = st;
        q[r][1]++;
      } else {
        q[++r][0] = st;
        q[r][1] = 1;
      }
    }
    if (op == 4) over = 0;
    if (op == 5) r = 0;
    if (op == 6) over++;
  }
  printf("%d", ans);
  return 0;
}
