#include <bits/stdc++.h>
using namespace std;
mt19937_64 rd(time(0));
template <typename T>
T gcd(T a, T b) {
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
template <typename T>
T max(T a, T b, T c, T d) {
  return max(a, max(b, c, d));
}
template <typename T>
T i_rand(T l, T r) {
  assert(l <= r);
  return uniform_int_distribution<T>(l, r)(rd);
}
template <typename T>
T r_rand(T l, T r) {
  return uniform_real_distribution<T>(l, r)(rd);
}
template <typename T>
void sfe(T a[], int l, int r) {
  shuffle(a + l, a + 1 + r, rd);
}
template <typename T>
void sfe(vector<T> a) {
  shuffle(a.begin(), a.end(), rd);
}
int n;
int v, novt = 0;
int rs = 0;
stack<int> sp_s;
signed main() {
  clock_t _, __;
  _ = clock();
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int t, s;
    cin >> t;
    if (t == 1) {
      cin >> s;
      v = s;
    }
    if (t == 2) {
      rs += novt;
      novt = 0;
    }
    if (t == 3) {
      cin >> s;
      sp_s.push(s);
    }
    if (t == 4) novt = 0;
    if (t == 5)
      while (!sp_s.empty()) sp_s.pop();
    if (t == 6) ++novt;
    while (!sp_s.empty() && sp_s.top() < v) {
      ++rs;
      sp_s.pop();
    }
  }
  cout << rs;
  __ = clock();
  double ___ = double(__ - _) / (double)CLOCKS_PER_SEC;
  cerr << "\nTime executed: " << setprecision(5) << fixed << ___ << " sec\n";
  return 0;
}
