#include <bits/stdc++.h>
using namespace std;
const int BLACK = 1, WHITE = 2;
int len_of_number(int n) {
  int len(0);
  while (n != 0) {
    ++len;
    n /= 10;
  }
  return len;
}
int sum_of_digits(int n) {
  int sod = 0;
  while (n != 0) {
    sod += (n % 10);
    n /= 10;
  }
  return sod;
}
bool isPalindrome(string str) {
  int n = str.length();
  for (int i = (0); i <= (n / 2); i++)
    if (str[i] != str[n - i - 1]) return false;
  return true;
}
long long int fast_exp(long long int x, long long int i) {
  long long int ans = 1;
  while (i > 0) {
    if (i & 1) ans = (ans * x);
    i >>= 1;
    x = (x * x);
  }
  return ans;
}
long long int fast_exp(long long int x, long long int i, long long int mod) {
  long long int ans = 1;
  while (i > 0) {
    if (i & 1) ans = (ans * x) % mod;
    i >>= 1;
    x = (x * x) % mod;
  }
  return ans;
}
long long int modInverse(long long int x, long long int mod) {
  return fast_exp(x, mod - 2, mod);
}
long long int egcd_x, egcd_y, egcd_d;
void egcd(long long int a, long long int b) {
  if (b == 0) {
    egcd_x = 1, egcd_y = 0;
    egcd_d = a;
    return;
  }
  egcd(b, a % b);
  long long int temp = egcd_x;
  egcd_x = egcd_y;
  egcd_y = temp - (a / b) * egcd_y;
}
long long int extended_gcd(long long int a, long long int b) {
  if (a >= b) {
    egcd(a, b);
    return ((egcd_x % b) + b) % b;
  } else {
    egcd(b, a);
    return ((egcd_y % b) + b) % b;
  }
}
long long int gcd(long long int x, long long int y) {
  long long int t;
  while (y != 0) {
    t = x % y;
    x = y;
    y = t;
  }
  return x;
}
bool isPrime(int n) {
  int root = sqrt(n);
  for (int i = (2); i <= (root); i++)
    if (n % i == 0) return 0;
  return 1;
}
vector<int> cnt;
string groupAndCnt(string str) {
  string a = "";
  int prev_count = 0;
  char prev_char = '~';
  for (auto &c : str) {
    if (c != prev_char) {
      if (prev_count) {
        a += prev_char;
        cnt.push_back(prev_count);
      }
      prev_count = 1;
      prev_char = c;
    } else
      ++prev_count;
  }
  cnt.push_back(prev_count);
  a += prev_char;
  return a;
}
vector<int> pset, sz;
int findSet(int i) { return (i == pset[i]) ? i : (pset[i] = findSet(i)); }
void unionSet(int i, int j) {
  int p1 = findSet(i);
  int p2 = findSet(j);
  if (p1 == p2)
    sz[p1] += 1;
  else {
    pset[i] = p2;
    sz[p2] += sz[p1];
  }
}
vector<int> segment_tree;
void init_segment_tree(int N) {
  int length = (int)(2 * pow(2.0, floor((log((double)N) / log(2.0)) + 1)));
  segment_tree.resize(length, 0);
}
vector<int> lazy_tree;
void init_lazy_tree(int N) {
  int length = (int)(2 * pow(2.0, floor((log((double)N) / log(2.0)) + 1)));
  lazy_tree.resize(length, 0);
}
void solve(int T) {
  int t, s;
  long long int n, ans = 0;
  cin >> n;
  long long int overtake_not_allowed = 0, current_speed;
  vector<int> speed_limit;
  for (int i = (1); i <= (n); i++) {
    cin >> t;
    switch (t) {
      case 1:
        cin >> s;
        if (speed_limit.empty() || *(--speed_limit.end()) >= s) {
          current_speed = s;
        } else {
          while (!speed_limit.empty() && *(--speed_limit.end()) < s)
            speed_limit.pop_back(), ++ans;
          current_speed = s;
        }
        break;
      case 2:
        if (overtake_not_allowed == 0) {
        } else {
          ans += overtake_not_allowed;
          overtake_not_allowed = 0;
        }
        break;
      case 3:
        cin >> s;
        if (current_speed <= s) {
          speed_limit.push_back(s);
        } else {
          ++ans;
        }
        break;
      case 4:
        overtake_not_allowed = 0;
        break;
      case 5:
        speed_limit.clear();
        break;
      case 6:
        overtake_not_allowed++;
        break;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int test_cases;
  test_cases = 1;
  for (int T = (0); T <= (test_cases - 1); T++) {
    solve(T);
  }
  return 0;
}
