#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long base = 10000007;
long long large = 1000000000000000000LL;
int main() {
  int q;
  cin >> q;
  vector<int> st1, st2;
  int cnt = 0;
  int can = 1;
  st1.push_back(500);
  st2.push_back(can);
  int cv = 0;
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &cv);
    }
    if (t == 2) {
      while (st2.back() == 0) {
        cnt++;
        st2.pop_back();
      }
    }
    if (t == 3) {
      int x;
      scanf("%d", &x);
      st1.push_back(x);
    }
    if (t == 4) {
      st2.push_back(1);
    }
    if (t == 5) {
      st1.push_back(500);
    }
    if (t == 6) {
      st2.push_back(0);
    }
    while (cv > st1.back()) {
      st1.pop_back();
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
