#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
void solve() {
  stack<int> SL({300});
  stack<bool> OT({true});
  int n, t, s;
  int speed = 0;
  int ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    switch (t) {
      case 1:
        cin >> speed;
        while (!SL.empty() && SL.top() < speed) {
          SL.pop();
          ++ans;
        }
        break;
      case 2:
        while (!OT.empty() && !OT.top()) {
          OT.pop();
          ++ans;
        }
        break;
      case 3:
        cin >> s;
        if (speed > s)
          ++ans;
        else
          SL.push(s);
        break;
      case 4:
        OT.push(true);
        break;
      case 5:
        SL.push(300);
        break;
      case 6:
        OT.push(false);
        break;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
