#include <bits/stdc++.h>
using namespace std;
const int MAXSP = 301;
stack<int> splmt;
int nt_cnt = 0;
int main() {
  int m = 0, code, sp, nextsp, cnt = 0;
  splmt.push(MAXSP);
  nt_cnt = 0;
  cin >> m;
  while (m--) {
    cin >> code;
    if (code == 1 || code == 3) cin >> nextsp;
    switch (code) {
      case 1: {
        while (splmt.top() < nextsp) {
          splmt.pop();
          cnt++;
        }
        sp = nextsp;
      } break;
      case 2: {
        if (nt_cnt > 0) cnt += nt_cnt;
        nt_cnt = 0;
      } break;
      case 3: {
        if (nextsp < sp)
          cnt++;
        else
          splmt.push(nextsp);
      } break;
      case 4: {
        nt_cnt = 0;
      } break;
      case 5: {
        while (!splmt.empty()) splmt.pop();
        splmt.push(MAXSP);
      } break;
      case 6: {
        nt_cnt++;
      } break;
    }
  }
  cout << cnt << endl;
}
