#include <bits/stdc++.h>
using namespace std;
int n, t[200100], Speed[200100];
stack<int> S;
void Clear() {
  while (!S.empty()) S.pop();
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    if (t[i] == 1 || t[i] == 3) cin >> Speed[i];
  }
  int cnt = 0, Ans = 0, currSpeed;
  for (int i = 0; i < n; i++) {
    if (t[i] == 1) {
      while (S.size() && S.top() < Speed[i]) Ans++, S.pop();
      currSpeed = Speed[i];
    }
    if (t[i] == 5) Clear();
    if (t[i] == 3 && Speed[i] < currSpeed)
      Ans++;
    else if (t[i] == 3)
      S.push(Speed[i]);
    if (t[i] == 2) Ans += cnt, cnt = 0;
    if (t[i] == 4) cnt = 0;
    if (t[i] == 6) cnt++;
  }
  cout << Ans;
  return 0;
}
