#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
int n, speed, ans;
int ty;
int splim[MAXN + 50], L;
int ovall;
int main() {
  scanf("%d", &n);
  for (; n--;) {
    scanf("%d", &ty);
    switch (ty) {
      case 1:
        scanf("%d", &speed);
        for (; L > 0 && speed > splim[L];) {
          ++ans;
          --L;
        }
        break;
      case 2:
        if (ovall) {
          ans += ovall;
          ovall = 0;
        }
        break;
      case 3:
        scanf("%d", &splim[++L]);
        for (; L > 0 && speed > splim[L];) {
          ++ans;
          --L;
        }
        break;
      case 4:
        ovall = 0;
        break;
      case 5:
        L = 0;
        break;
      case 6:
        ++ovall;
        break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
