#include <bits/stdc++.h>
using namespace std;
long long int ans[1000001];
stack<long long int> st1;
stack<pair<long long int, long long int> > st2;
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j, n, q, x, y, cur_speed, speed_limit, overtake, res = 0,
                                                                    type, id;
  cin >> q;
  cin >> x >> y;
  cur_speed = y;
  overtake = 1;
  q--;
  for (i = 1; i <= q; i++) {
    cin >> type;
    if (type == 1) {
      cin >> cur_speed;
      while (st2.size()) {
        id = st2.top().first;
        if (cur_speed <= st2.top().second) break;
        ans[id] = 1;
        st2.pop();
      }
    } else if (type == 2) {
      while (st1.size()) {
        ans[st1.top()] = 1;
        st1.pop();
      }
    } else if (type == 3) {
      cin >> speed_limit;
      st2.push({i, speed_limit});
      while (st2.size()) {
        id = st2.top().first;
        if (cur_speed <= st2.top().second) break;
        ans[id] = 1;
        st2.pop();
      }
    } else if (type == 4) {
      overtake = 1;
      while (st1.size()) st1.pop();
    } else if (type == 5) {
      speed_limit = 1000000000000;
      while (st2.size()) st2.pop();
    } else if (type == 6) {
      overtake = 0;
      st1.push(i);
    }
  }
  for (i = 1; i <= q; i++) res += ans[i];
  cout << res;
  return 0;
}
