#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int overtake = 0;
  int ans = 0;
  stack<int> pilha;
  int speed = 0x3f3f3f3f;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    switch (s) {
      case 1:
        cin >> speed;
        while (!pilha.empty() and pilha.top() < speed) {
          ans++;
          pilha.pop();
        }
        break;
      case 2:
        ans += overtake;
        overtake = 0;
        break;
      case 3:
        int sp;
        cin >> sp;
        if (speed > sp)
          ans++;
        else
          pilha.push(sp);
        break;
      case 4:
        overtake = 0;
        break;
      case 5:
        pilha = stack<int>();
        break;
      case 6:
        overtake += 1;
        break;
      default:
        break;
    }
  }
  cout << ans << endl;
  return 0;
}
