#include <bits/stdc++.h>
using namespace std;
long long n, t, s, ans = 0, cnt = 0, speed;
vector<long long> slim;
void scan(long long &x) {
  long long res = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') res = res * 10 + c - '0', c = getchar();
  x = res;
  return;
}
int main() {
  long long i, j, k, l, r, mid;
  scan(n);
  for (i = 1; i <= n; i++) {
    scan(t);
    if (t == 1 || t == 3) {
      scan(s);
      if (t == 3) {
        if (s >= speed)
          slim.push_back(s);
        else
          ans++;
      } else {
        speed = s;
        while (!slim.empty()) {
          if (slim.back() < speed) {
            slim.pop_back();
            ans++;
          } else
            break;
        }
      }
    }
    if (t == 6) cnt++;
    if (t == 5) slim.clear();
    if (t == 4) cnt = 0;
    if (t == 2) {
      ans += cnt;
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
