#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = ans * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
int n;
pair<int, int> p[200005];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int v = 0, sta = 0, more = 0, ma = 2e9, ans = 0, l = 1, r = 0;
  for (int i = 1; i <= n; i++) {
    int s, t;
    cin >> s;
    int now;
    if (s == 1) {
      cin >> now;
      v = now;
      if (now <= p[r].first) {
        continue;
      }
      while (p[r].first < now && r >= 1) {
        r--;
        ans++;
      }
    } else if (s == 2) {
      if (more) ans += more, more = 0;
    } else if (s == 3) {
      cin >> now;
      if (now < v) {
        ans++;
        continue;
      }
      p[++r] = {now, i};
    } else if (s == 4) {
      more = 0;
    } else if (s == 5) {
      ma = 2e9;
      r = 0;
    } else {
      more++;
    }
  }
  cout << ans;
  return 0;
}
