#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9 + 42;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n = 0, ans = 0;
  cin >> n;
  int obg = 0, cspeed = 0;
  vector<int> lim;
  lim.push_back(inf);
  for (int act = 0; act < n; act++) {
    int t = 0;
    cin >> t;
    if (t == 1) {
      int s;
      cin >> s;
      cspeed = s;
      while (lim.back() < cspeed) {
        ans++;
        lim.pop_back();
      }
    } else if (t == 2) {
      ans += obg;
      obg = 0;
    } else if (t == 3) {
      int s;
      cin >> s;
      if (s < cspeed)
        ans++;
      else
        lim.push_back(s);
    } else if (t == 4)
      obg = 0;
    else if (t == 5) {
      lim.clear();
      lim.push_back(inf);
    } else
      obg++;
  }
  cout << ans;
  return 0;
}
