#include <bits/stdc++.h>
using namespace std;
const int Inf = 2147483647;
int main() {
  int n;
  cin >> n;
  int t[n + 1];
  int p;
  int ans = 0, v = 0, l1 = 0, f1 = 0, p1 = 0;
  stack<int> s1;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    switch (t[i]) {
      case 1: {
        cin >> p;
        int sum1 = 0;
        while (!s1.empty() && s1.top() < p) {
          sum1++;
          s1.pop();
        }
        ans += sum1;
        v = p;
        break;
      }
      case 2: {
        ans += p1;
        p1 = 0;
        break;
      }
      case 3: {
        cin >> p;
        s1.push(p);
        int sum1 = 0;
        while (!s1.empty() && s1.top() < v) {
          sum1++;
          s1.pop();
        }
        ans += sum1;
        break;
      }
      case 4: {
        p1 = 0;
        break;
      }
      case 5: {
        while (!s1.empty()) s1.pop();
        break;
      }
      case 6: {
        p1++;
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
