#include <bits/stdc++.h>
using namespace std;
stack<int> sl;
int how_many(int s) {
  int ret = 0;
  while (!sl.empty() && sl.top() < s) {
    ret++;
    sl.pop();
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, s, o = 0, ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t, nsl;
    cin >> t;
    switch (t) {
      case 1:
        cin >> s;
        ans += how_many(s);
        break;
      case 2:
        ans += o;
        o = 0;
        break;
      case 3:
        cin >> nsl;
        sl.push(nsl);
        ans += how_many(s);
        break;
      case 4:
        o = 0;
        break;
      case 5:
        how_many(300);
        break;
      case 6:
        o++;
        break;
    }
  }
  cout << ans << endl;
  return 0;
}
