#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... second) {
  long long int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), second...);
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int count = 0;
  long long int speed = 0;
  stack<long long int> S;
  S.push(1000000007);
  long long int overtake = 0;
  for (long long int i = (long long int)1; i <= (long long int)n; i++) {
    long long int a, b;
    cin >> a;
    switch (a) {
      case 1:
        cin >> b;
        speed = b;
        while (b > S.top()) {
          count++;
          S.pop();
        }
        break;
      case 2:
        count += overtake;
        overtake = 0;
        break;
      case 3:
        cin >> b;
        S.push(b);
        while (speed > S.top()) {
          count++;
          S.pop();
        }
        break;
      case 4:
        overtake = 0;
        break;
      case 5:
        while (S.top() != 1000000007) {
          S.pop();
        }
        break;
      case 6:
        overtake++;
        break;
    }
  }
  cout << count << endl;
  return 0;
}
