#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
const long long p = 1e9 + 7;
vector<int> v;
int a[2];
int main() {
  int n, i, j, t, s, f = 0, ans = 0;
  cin >> n;
  v.push_back(1000);
  for (i = 0; i < n; i++) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &s);
      while (s > v.back()) {
        ans++;
        v.pop_back();
      }
    }
    if (t == 2) {
      ans += f;
      f = 0;
    }
    if (t == 3) {
      int x;
      scanf("%d", &x);
      if (x >= s)
        v.push_back(x);
      else
        ans++;
    }
    if (t == 4) {
      f = 0;
    }
    if (t == 5) {
      while (v.size() > 1) v.pop_back();
    }
    if (t == 6) {
      f++;
    }
  }
  printf("%d", ans);
  return 0;
}
