#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
vector<int> b;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  b.resize(n);
  int top = 0;
  int ans = 0;
  int no = 0;
  int sp;
  b[0] = inf;
  int type, x;
  while (n--) {
    cin >> type;
    if (type == 1) cin >> sp;
    if (type == 2) ans += no, no = 0;
    if (type == 3) cin >> x, b[++top] = x;
    if (type == 4) no = 0;
    if (type == 5) b[++top] = 1e9;
    if (type == 6) no++;
    while (b[top] < sp) top--, ans++;
  }
  cout << ans << '\n';
  return 0;
}
