#include <bits/stdc++.h>
using namespace std;
int main() {
  stack<int> s;
  int sp = 0;
  int c = 0, cnt = 0;
  int n;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    if (x == 1) cin >> sp;
    if (x == 6) cnt++;
    if (x == 4) cnt = 0;
    if (x == 2) {
      c += cnt;
      cnt = 0;
    }
    if (x == 5) {
      while (!s.empty()) s.pop();
    }
    if (x == 3) {
      int maxs;
      cin >> maxs;
      s.push(maxs);
    }
    while (!s.empty() && sp > s.top()) {
      s.pop();
      c++;
    }
  }
  cout << c << endl;
}
