#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, ats = 0, x, v = 0, limit;
  int overtake_signs = 0;
  stack<int> limits;
  cin >> n;
  while (n--) {
    cin >> x;
    if (x == 1) {
      cin >> v;
      while (!limits.empty() && limits.top() < v) limits.pop(), ats++;
    } else if (x == 2)
      ats += overtake_signs, overtake_signs = 0;
    else if (x == 3) {
      cin >> limit;
      limits.push(limit);
      while (!limits.empty() && limits.top() < v) limits.pop(), ats++;
    } else if (x == 4)
      overtake_signs = 0;
    else if (x == 5) {
      while (!limits.empty()) limits.pop();
    } else if (x == 6)
      overtake_signs++;
  }
  cout << ats;
  return 0;
}
