#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, t, ans = 0, present_speed, i;
  cin >> n;
  stack<int> speed_limit;
  int overtakes = 0, limit;
  for (i = 0; i < n; i++) {
    cin >> t;
    if (t == 1)
      cin >> present_speed;
    else if (t == 2) {
      if (overtakes != 0) ans += overtakes;
      overtakes = 0;
    } else if (t == 3) {
      cin >> limit;
      speed_limit.push(limit);
    } else if (t == 4)
      overtakes = 0;
    else if (t == 5) {
      while (!speed_limit.empty()) speed_limit.pop();
    } else
      overtakes++;
    while (!speed_limit.empty() && present_speed > speed_limit.top()) {
      ans++;
      speed_limit.pop();
    }
  }
  cout << ans << "\n";
}
