#include <bits/stdc++.h>
using namespace std;
int n, speed, speedlimit[200005], overallow, ans, op;
int main() {
  cin >> n;
  speedlimit[0] = 400, overallow = 0;
  while (n--) {
    int a;
    cin >> a;
    if (a == 1) {
      cin >> a;
      speed = a;
      while (speedlimit[op] < speed) {
        op--;
        ans++;
      }
    } else if (a == 2) {
      ans += overallow;
      overallow = 0;
    } else if (a == 3) {
      cin >> a;
      speedlimit[++op] = a;
      while (speedlimit[op] < speed) {
        op--;
        ans++;
      }
    } else if (a == 4) {
      overallow = 0;
    } else if (a == 5) {
      speedlimit[++op] = 400;
    } else if (a == 6) {
      overallow++;
    }
  }
  cout << ans;
  return 0;
}
