#include <bits/stdc++.h>
using namespace std;
vector<int> speed;
int overtake = 0;
int speedf(int s) {
  if (speed.size() == 0)
    return 0;
  else {
    int i = 0;
    while (speed.size() != 0) {
      if (speed[speed.size() - 1] >= s)
        break;
      else {
        i = i + 1;
        speed.pop_back();
      }
    }
    return i;
  }
}
int main() {
  ios::sync_with_stdio(false);
  int i = 0, j, k, l, m, t, T, x, y, n, z, h;
  string s;
  cin >> y;
  cin >> k >> m;
  z = 0;
  vector<int> temp1;
  for (h = 1; h < y; h++) {
    cin >> k;
    if (k == 1) {
      cin >> m;
    }
    if (k == 3) {
      cin >> n;
      vector<int> temp;
      speed.push_back(n);
    }
    if (k == 5) {
      speed.clear();
    }
    if (k == 4) overtake = 0;
    if (k == 6) overtake++;
    if (k == 2) {
      z = z + overtake;
      overtake = 0;
    }
    z = z + speedf(m);
  }
  cout << z << endl;
  return 0;
}
