#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
long long mod = 1000000009;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
bool is_vowel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y')
    return 1;
  return 0;
}
long double getDistance(long double x1, long double y1, long double x2,
                        long double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
long long extended_euclidean(long long a, long long b, long long &x,
                             long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long g = extended_euclidean(b, a % b, y, x);
  y -= (a / b) * x;
  return g;
}
long long power(long long base, long long p) {
  if (p == 1) return base;
  if (!p) return 1ll;
  long long ret = power(base, p / 2);
  ret *= ret;
  ret %= mod;
  if (p & 1) ret *= base;
  return ret % mod;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> speed;
  int cur = 0;
  int overtake = 0, overtakesigns = 0;
  int sum = 0;
  for (int i = (0); i <= (n - 1); ++i) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &cur);
    }
    if (type == 2) {
      if (overtake) {
        sum += overtakesigns;
        overtakesigns = overtake = 0;
      }
    }
    if (type == 3) {
      int limit;
      scanf("%d", &limit);
      speed.push_back(limit);
    }
    if (type == 4) {
      overtake = overtakesigns = 0;
    }
    if (type == 5) {
      speed.clear();
    }
    if (type == 6) {
      overtake = 1;
      overtakesigns++;
    }
    while (speed.size() && speed.back() < cur) {
      sum++;
      speed.pop_back();
    }
  }
  cout << sum;
  return 0;
}
