#include <bits/stdc++.h>
using namespace std;
stack<int> sta;
int main() {
  int n, t, s;
  scanf("%d", &n);
  int cnt = 0;
  int ans = 0;
  int speed = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &s);
      speed = s;
      while (!sta.empty() && sta.top() < speed) {
        ans++;
        sta.pop();
      }
    }
    if (t == 2) {
      ans += cnt;
      cnt = 0;
    }
    if (t == 3) {
      scanf("%d", &s);
      if (speed > s)
        ans++;
      else
        sta.push(s);
    }
    if (t == 4) cnt = 0;
    if (t == 5) {
      while (!sta.empty()) sta.pop();
    }
    if (t == 6) cnt++;
  }
  printf("%d\n", ans);
  return 0;
}
