#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 3e5 + 5;
const long long INF = 1e14;
int main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  stack<long long> v;
  stack<bool> o;
  o.push(true);
  v.push(0);
  long long ans = 0;
  long long cur = 0;
  for (long long i = 0; i < n; i++) {
    int t;
    cin >> t;
    int s;
    if (t == 1 | t == 3) cin >> s;
    if (t == 1) {
      cur = s;
      while (v.top() != 0 && v.top() < cur) {
        ans++;
        v.pop();
      }
    } else if (t == 2) {
      while (!o.top()) {
        ans++;
        o.pop();
      }
    } else if (t == 3) {
      v.push(s);
      while (v.top() != 0 && cur > v.top()) {
        ans++;
        v.pop();
      }
    } else if (t == 4) {
      o.push(true);
    } else if (t == 5) {
      v.push(0);
    } else {
      o.push(false);
    }
  }
  cout << ans << "\n";
  return 0;
}
