#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> v;
  long long ovr = 0, ans = 0, spd, val;
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    long long t;
    cin >> t;
    if (t == 5)
      v.clear();
    else if (t == 6)
      ovr++;
    else if (t == 4)
      ovr = 0;
    else if (t == 2)
      ans += ovr, ovr = 0;
    else {
      cin >> val;
      if (t == 1)
        spd = val;
      else
        v.push_back(val);
      long long j = v.size() - 1;
      while (j >= 0 && spd > v[j]) {
        v.pop_back();
        ans++;
        j--;
      }
    }
  }
  cout << ans;
}
