#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... s) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
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, t, s, ans = 0, sp, no;
  cin >> n;
  cin >> t >> s;
  sp = s, no = 0;
  stack<long long int> sl;
  sl.push(1000);
  for (long long int i = (long long int)(2); i <= (long long int)(n); i++) {
    cin >> t;
    if (t == 1 || t == 3) cin >> s;
    if (t == 1) {
      sp = s;
      while (sp > sl.top()) {
        ans++;
        sl.pop();
      }
    } else if (t == 2) {
      ans += no;
      no = 0;
    } else if (t == 3) {
      if (s < sp)
        ans++;
      else
        sl.push(s);
    } else if (t == 4) {
      no = 0;
    } else if (t == 5) {
      sl.push(1000);
    } else
      no++;
  }
  cout << ans;
}
