#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1e6;
stack<int> lim;
stack<bool> mov;
int n, ans, now;
int main() {
  lim.push(1e9);
  mov.push(true);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int type;
    cin >> type;
    switch (type) {
      case 1: {
        int to;
        cin >> to;
        now = to;
        while (to > lim.top()) {
          lim.pop();
          ans++;
        }
        break;
      }
      case 2: {
        while (!mov.top()) {
          mov.pop();
          ans++;
        }
        break;
      }
      case 3: {
        int to;
        cin >> to;
        if (to >= now)
          lim.push(to);
        else
          ans++;
        break;
      }
      case 4: {
        mov.push(true);
        break;
      }
      case 5: {
        lim.push(1e9);
        break;
      }
      case 6: {
        mov.push(false);
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
