#include <bits/stdc++.h>
using namespace std;
stack<int> s;
int main() {
  int n, ans = 0, cnt = 0, cur = 0;
  scanf("%d", &n);
  while (n--) {
    int t, val;
    scanf("%d", &t);
    if (t == 1 || t == 3) scanf("%d", &val);
    if (t == 1) {
      cur = val;
      while (s.size() && cur > s.top()) {
        ans++;
        s.pop();
      }
    }
    if (t == 2) {
      ans += cnt;
      cnt = 0;
    }
    if (t == 3) {
      s.push(val);
      if (s.size() && cur > s.top()) {
        ans++;
        s.pop();
      }
    }
    if (t == 4) cnt = 0;
    if (t == 5) {
      while (!s.empty()) s.pop();
    }
    if (t == 6) cnt++;
  }
  printf("%d\n", ans);
  return 0;
}
