#include <bits/stdc++.h>
using namespace std;
const int N = 200004;
int main() {
  int n;
  scanf("%d", &n);
  int i;
  stack<int> stk;
  int id = 0;
  stk.push(1000);
  int sum = 0, s;
  int pr = -1;
  while (n--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &s);
      int val = 0;
      while (stk.top() < s) {
        stk.pop();
        val++;
      }
      sum += val;
      pr = s;
    } else if (t == 2) {
      sum += id;
      id = 0;
    } else if (t == 3) {
      scanf("%d", &s);
      if (s < pr)
        sum++;
      else
        stk.push(s);
    } else if (t == 4)
      id = 0;
    else if (t == 5)
      stk.push(1000);
    else
      id++;
  }
  printf("%d\n", sum);
  return 0;
}
