#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e7 + 7;
const double pi = 3.1415926535898;
const double eps = 1e-9;
const int MAXN = 2e5 + 10;
const int N = 1e3 + 10;
stack<int> speed;
stack<int> overlimit;
int nowspeed = 0;
void solve() {
  int n;
  scanf("%d", &n);
  int t, x;
  int ans = 0;
  while (n--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &x);
      while (!speed.empty()) {
        int y = speed.top();
        if (x > y) {
          speed.pop();
          ans++;
        } else {
          break;
        }
      }
      nowspeed = x;
    } else if (t == 2) {
      while (!overlimit.empty()) {
        ans++;
        overlimit.pop();
      }
    } else if (t == 3) {
      scanf("%d", &x);
      if (nowspeed <= x) {
        speed.push(x);
      } else {
        ans++;
      }
    } else if (t == 4) {
      while (!overlimit.empty()) {
        overlimit.pop();
      }
    } else if (t == 5) {
      while (!speed.empty()) {
        speed.pop();
      }
    } else if (t == 6) {
      overlimit.push(1);
    }
  }
  printf("%d\n", ans);
}
int main() {
  solve();
  return 0;
}
