#include <bits/stdc++.h>
using namespace std;
stack<long long> q;
struct node {
  long long type, x;
} t[2000005];
int main() {
  long long n, v = 0, p = 0, ans = 0, lim = 2000005;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &t[i].type);
    if (t[i].type == 1 || t[i].type == 3) scanf("%lld", &t[i].x);
    if (t[i].type == 1) {
      v = t[i].x;
      while (lim < v && !q.empty()) {
        ans++;
        q.pop();
        if (q.empty())
          lim = 2000005;
        else
          lim = q.top();
      }
    } else if (t[i].type == 2) {
      ans += p;
      p = 0;
    } else if (t[i].type == 3) {
      if (v > t[i].x)
        ans++;
      else
        lim = t[i].x, q.push(t[i].x);
    } else if (t[i].type == 4)
      p = 0;
    else if (t[i].type == 5) {
      while (!q.empty()) q.pop();
      lim = 2000005;
    } else if (t[i].type == 6)
      p++;
  }
  printf("%lld", ans);
  return 0;
}
