#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long Hashimoto = 0;
  bool Kanna = 1;
  char I_Love = getchar();
  while (I_Love < '0' || I_Love > '9') {
    if (I_Love == '-') Kanna = 0;
    I_Love = getchar();
  }
  while (I_Love >= '0' && I_Love <= '9') {
    Hashimoto = Hashimoto * 10 + I_Love - '0';
    I_Love = getchar();
  }
  return (Kanna ? Hashimoto : -Hashimoto);
}
template <typename T1, typename T2>
inline void Umax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
inline void Umin(T1 &a, T2 b) {
  if (a > b) a = b;
}
int n;
int ans = 0;
int c;
stack<int> a;
int b;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  n = read();
  while (n--) {
    int typo = read();
    switch (typo) {
      case 1: {
        c = read();
        while (a.size() && a.top() < c) {
          a.pop();
          ans++;
        }
        break;
      }
      case 3: {
        int x = read();
        if (x < c)
          ans++;
        else
          a.push(x);
        break;
      }
      case 5: {
        a.push((1000000000));
        break;
      }
      case 2: {
        ans += b;
        b = 0;
        break;
      }
      case 4: {
        b = 0;
        break;
      }
      case 6: {
        b++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
