#include <bits/stdc++.h>
using namespace std;
pair<int, int> Array[200005];
stack<int> S;
int main() {
  int N, i, j, type;
  int Cur, Ans = 0;
  int Count = 0;
  scanf("%d", &N);
  for (i = 1, j = 1; i <= N; ++i) {
    scanf("%d", &type);
    switch (type) {
      case 1: {
        scanf("%d", &Array[j].second);
        Array[j++].first = 1;
        break;
      }
      case 2: {
        Ans += Count;
        Count = 0;
        break;
      }
      case 3: {
        scanf("%d", &Array[j].second);
        Array[j++].first = 3;
        break;
      }
      case 4: {
        Count = 0;
        break;
      }
      case 5: {
        Array[j++].first = 5;
        break;
      }
      default:
        ++Count;
    }
  }
  int limit = --j;
  Cur = Array[1].second;
  for (i = 2; i <= limit; ++i) {
    if (Array[i].first == 1) {
      Cur = Array[i].second;
      while (!S.empty()) {
        if (S.top() < Cur) {
          ++Ans;
          S.pop();
        } else
          break;
      }
    } else if (Array[i].first == 3) {
      if (Array[i].second < Cur)
        ++Ans;
      else
        S.push(Array[i].second);
    } else {
      while (!S.empty()) S.pop();
    }
  }
  printf("%d\n", Ans);
  return 0;
}
