#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  int n;
  cin >> n;
  stack<int> mxped;
  stack<int> ovt;
  mxped.push(301);
  ovt.push(true);
  int cspe = 0;
  int ans = 0;
  while (n--) {
    int x;
    cin >> x;
    switch (x) {
      case 1:
        cin >> cspe;
        break;
      case 2:
        while (ovt.top() == false) ovt.pop(), ans++;
        break;
      case 3:
        int v;
        cin >> v;
        mxped.push(v);
        break;
      case 4:
        ovt.push(true);
        break;
      case 5:
        mxped.push(310);
        break;
      case 6:
        ovt.push(false);
        break;
    }
    while (mxped.top() < cspe) mxped.pop(), ans++;
  }
  cout << ans << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
