#include <bits/stdc++.h>
using namespace std;
const int inf = 500;
struct action {
  int tp;
  int val;
  action() {
    tp = -1;
    val = 2000000;
  }
} act[200005];
int spe[200005];
int ovt[200005];
int speed[200005];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int o, p;
    int nowspeed = 0;
    int nowlimit = inf;
    bool nowovertake = true;
    bool speedsign = true;
    bool overtakesign = true;
    int cnt = 0;
    int tot1 = 0;
    int tot2 = 0;
    int tot3 = 0;
    int tots = 0;
    spe[tot2++] = inf;
    ovt[tot3++] = 1;
    for (int i = 0; i < n; i++) {
      scanf("%d", &o);
      if (o == 1 || o == 3) scanf("%d", &p);
      if (o == 1 || o == 2) {
        if (o == 1) {
          nowspeed = p;
          while (nowspeed > spe[tot2 - 1] && tot2) cnt++, tot2--;
        } else {
          while (ovt[tot3 - 1] == 0 && tot3) cnt++, tot3--;
        }
      }
      if (o == 3 || o == 5) {
        if (o == 3) {
          if (nowspeed <= p)
            spe[tot2++] = p;
          else
            cnt++;
        } else
          spe[tot2++] = inf;
      }
      if (o == 6 || o == 4) {
        if (o == 6)
          ovt[tot3++] = 0;
        else
          ovt[tot3++] = 1;
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
