#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, x, y, flag = 1, ans = 0, t = 0, tt = 0;
  int a[200000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == 1) {
      cin >> x;
      while (x > a[tt] && tt > 0) {
        ans++;
        tt--;
      }
    }
    if (s == 3) {
      cin >> y;
      if (y < x)
        ans++;
      else {
        tt++;
        a[tt] = y;
      }
    }
    if (s == 2) {
      if (flag == 0) ans = ans + t;
      t = 0;
    }
    if (s == 4) {
      flag = 1;
      t = 0;
    }
    if (s == 6) {
      flag = 0;
      t++;
    }
    if (s == 5) {
      tt = 0;
    }
  }
  cout << ans;
  return 0;
}
