#include <bits/stdc++.h>
using namespace std;
const int maxn = 200050;
int n, ans, op[maxn], x[maxn];
int j5[maxn], j4[maxn];
set<int> tr[7];
set<int>::iterator it;
int tmpv;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &op[i]);
    if (op[i] == 1 || op[i] == 3) scanf("%d", &x[i]);
    tr[op[i]].insert(i);
    if (op[i] == 4) j4[i]++;
    if (op[i] == 5) j5[i]++;
  }
  for (int i = 1; i <= n; ++i) j4[i] += j4[i - 1], j5[i] += j5[i - 1];
  for (int i = 1; i <= n; ++i) {
    if (op[i] == 1) {
      it = tr[3].lower_bound(i);
      if (it == tr[3].begin()) continue;
      --it;
      while (1) {
        if (j5[i] - j5[(*it) - 1]) break;
        if (x[*it] >= x[i]) break;
        ++ans;
        tmpv = (*it);
        if (it == tr[3].begin()) {
          tr[3].erase(tmpv);
          break;
        }
        --it;
        tr[3].erase(tmpv);
      }
    } else if (op[i] == 2) {
      it = tr[6].lower_bound(i);
      if (it == tr[6].begin()) continue;
      --it;
      while (1) {
        if (j4[i] - j4[(*it) - 1]) break;
        ++ans;
        tmpv = (*it);
        if (it == tr[6].begin()) {
          tr[6].erase(tmpv);
          break;
        }
        --it;
        tr[6].erase(tmpv);
      }
    } else if (op[i] == 3) {
      it = tr[1].lower_bound(i);
      --it;
      if (x[(*it)] > x[i]) {
        ++ans;
        tr[3].erase(tr[3].lower_bound(i));
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
