#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 20;
const double eps = 1e-8;
int n;
int main() {
  while (cin >> n) {
    int ans = 0;
    int f, ovl = 0, spl = INF, spd = 0, noti = 0;
    deque<int> q;
    while (n--) {
      scanf("%d", &f);
      if (f == 1) {
        int t;
        scanf("%d", &spd);
        while (!q.empty() && q.back() < spd) q.pop_back(), ans++;
      } else if (f == 3) {
        scanf("%d", &spl);
        q.push_back(spl);
        while (!q.empty() && q.back() < spd) q.pop_back(), ans++;
      } else if (f == 2)
        ans += ovl, ovl = 0;
      else if (f == 4)
        ovl = 0;
      else if (f == 5) {
        spl = INF;
        while (!q.empty()) q.pop_back();
      } else if (f == 6)
        ovl++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
