#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18, MAXN = 2e5, MOD = 1e9;
long long NOD(long long NOD1, long long NOD2) {
  while (NOD2) {
    NOD1 %= NOD2;
    swap(NOD1, NOD2);
  }
  return NOD1;
}
long long NOK(long long NOK1, long long NOK2) {
  return NOK1 * NOK2 / NOD(NOK1, NOK2);
}
long long s, d, n, k, o = INF;
deque<long long> q;
deque<long long> qp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  q.push_front(INF);
  cin >> n;
  for (int x, i = 0; i < n; i++) {
    cin >> x;
    if (x == 1) {
      cin >> s;
      while (q.front() < s) {
        k++;
        q.pop_front();
      }
    } else if (x == 2) {
      if (d) k += d;
      d = 0;
    } else if (x == 3) {
      cin >> o;
      if (s > o)
        k++;
      else
        q.push_front(o);
    } else if (x == 4) {
      d = 0;
    } else if (x == 5) {
      o = INF;
      q = qp;
      q.push_front(INF);
    } else if (x == 6) {
      d++;
    }
  }
  cout << k;
}
