#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int cnt;
int n;
int main() {
  cin >> n;
  int ans = 0;
  stack<int> S;
  S.push(INF);
  int V;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d", &a);
    if (a == 1) {
      scanf("%d", &b);
      V = b;
      while (V > S.top()) {
        S.pop();
        ans++;
      }
    } else if (a == 3) {
      scanf("%d", &b);
      if (V > b)
        ans++;
      else
        S.push(b);
    } else if (a == 5) {
      while (S.top() - INF) S.pop();
    } else if (a == 2) {
      ans += cnt;
      cnt = 0;
    } else if (a == 4) {
      cnt = 0;
    } else {
      cnt++;
    }
  }
  cout << ans << endl;
}
