#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(5);
  a[1] = 400;
  a[2] = 1;
  a[4] = 0;
  int stt, v, ans = 0;
  vector<int> speed;
  for (int i = 0; i < n; i++) {
    cin >> stt;
    if (stt == 1) {
      cin >> a[0];
      while (speed.size() > 0) {
        if (a[0] > speed[speed.size() - 1]) {
          ans++;
          speed.pop_back();
        } else {
          break;
        }
      }
    }
    if (stt == 3) {
      cin >> a[1];
      if (a[0] > a[1]) {
        ans++;
      } else
        speed.push_back(a[1]);
    }
    if (stt == 5) {
      while (speed.size() > 0) speed.pop_back();
    }
    if (stt == 2) {
      ans += a[4];
      a[4] = 0;
    }
    if (stt == 4) {
      a[4] = 0;
    }
    if (stt == 6) {
      a[4]++;
    }
  }
  cout << ans << endl;
  return 0;
}
