#include <bits/stdc++.h>
const double pi = acos(-1.0);
const double eps = 1e-9;
const double deg = pi / 180;
const int inf = 2 * 1e9;
const int base = 2011;
const int raz = 2e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  n--;
  int ans = 0, t, c, second, cnt = 0;
  scanf("%d %d", &t, &second);
  vector<int> lim;
  while (n--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &c);
      if (c > second)
        while (!lim.empty()) {
          int l = lim.back();
          if (c > l) {
            ans++;
            lim.pop_back();
          } else
            break;
        }
      second = c;
    } else if (t == 3) {
      scanf("%d", &c);
      if (second > c)
        ans++;
      else
        lim.push_back(c);
    } else if (t == 2) {
      ans += cnt;
      cnt = 0;
    } else if (t == 5)
      lim.clear();
    else if (t == 4)
      cnt = 0;
    else if (t == 6)
      cnt++;
  }
  printf("%d", ans);
  return 0;
}
