#include <bits/stdc++.h>
using namespace std;
long long d, x, y;
void extendedEuclid(long long A, long long B) {
  if (B == 0) {
    d = A;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(B, A % B);
    int temp = x;
    x = y;
    y = temp - (A / B) * y;
  }
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
map<long long, long long> par, val;
void ini() {
  for (long long i = 0; i < 500010; i++) {
    par[i] = i;
  }
}
long long root(long long x) {
  while (par[x] != x) {
    par[x] = par[par[x]];
    x = par[x];
  }
  return x;
}
void uni(long long x, long long y) {
  x = root(x);
  y = root(y);
  par[y] = par[x];
}
int gcdExtended(int a, int b, int *x, int *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
int modInverse(int b, int m) {
  int x, y;
  int g = gcdExtended(b, m, &x, &y);
  if (g != 1) return -1;
  return (x % m + m) % m;
}
long long isPrime(long long n) {
  if (n == 0 || n == 1) return n;
  if (n % 2 == 0) return (long long)2;
  if (n % 3 == 0)
    return (long long)3;
  else {
    for (long long i = 5; i * i <= n; i += 6) {
      if (n % i == 0) return i;
      if (n % (i + 2) == 0) return (i + 2);
    }
    return n;
  }
}
const long long N = 10000010;
vector<bool> prime(N);
vector<long long> spf(N);
void sieve() {
  fill(prime.begin(), prime.end(), true);
  prime[1] = false;
  prime[0] = false;
  long long i, j;
  for (i = 2; i * i <= N; i++) {
    if (prime[i] == true) {
      spf[i] = i;
      for (j = i * i; j < N; j += i) {
        prime[j] = false;
        if (spf[j] == 0) spf[j] = i;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, i, j, k, m;
  cin >> n;
  long long ans = 0;
  bool ot = true;
  long long speed = LONG_LONG_MAX, curr = LONG_LONG_MAX;
  long long p = 0, q = 0;
  vector<long long> v;
  while (n--) {
    cin >> k;
    if (k == 1) {
      cin >> j;
      curr = j;
      if (curr > speed) {
        while (v.size() > 0 && v.back() < curr) {
          v.pop_back();
          ans++;
        }
      }
    }
    if (k == 2) {
      if (ot == false) {
        ans += p;
        p = 0;
      }
    }
    if (k == 3) {
      cin >> j;
      speed = j;
      v.push_back(speed);
      if (curr > speed) {
        while (v.size() > 0 && v.back() < curr) {
          v.pop_back();
          ans++;
        }
      }
    }
    if (k == 4) {
      ot = true;
      p = 0;
    }
    if (k == 5) {
      speed = LONG_LONG_MAX;
      v.resize(0);
      q = 0;
    }
    if (k == 6) {
      ot = false;
      p++;
    }
  }
  cout << ans;
}
