#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, t, v(0), x, ans(0), vel[200005], ob[200005], sz1(0), sz2(0);
  vel[0] = 400;
  ob[0] = 1;
  bool was(false);
  cin >> n;
  cin >> t >> v;
  for (int i(1); i < n; ++i) {
    cin >> t;
    if (t == 1 || t == 3) {
      cin >> x;
      if (t == 1) v = x;
      if (t == 3) vel[++sz1] = x;
      while (v > vel[sz1] && sz1 > 0) {
        sz1--;
        ans++;
      }
    } else if (t == 2) {
      while (ob[sz2] == -1 && sz2 > 0) {
        sz2--;
        ans++;
      }
    } else if (t == 4)
      ob[++sz2] = 1;
    else if (t == 5)
      vel[++sz1] = 400;
    else if (t == 6)
      ob[++sz2] = -1;
  }
  cout << ans;
  cin.get();
  cin.get();
  return 0;
}
