#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, i, j, x, t, y;
  cin >> n;
  long long cur = 0;
  long long ot = 0;
  long long ans = 0;
  vector<long long> mx;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (x == 1) {
      cin >> y;
      cur = y;
      while (!mx.empty() && cur > mx.back()) {
        ans++;
        mx.pop_back();
      }
    } else if (x == 2) {
      ans += ot;
      ot = 0;
    } else if (x == 3) {
      cin >> y;
      if (cur > y)
        ans++;
      else
        mx.push_back(y);
    } else if (x == 4) {
      ot = 0;
    } else if (x == 5) {
      mx.push_back(1000);
    } else {
      ot++;
    }
  }
  cout << ans;
}
