#include <bits/stdc++.h>
using namespace std;
long long n, i = 0, x, y, ans = 0, s;
map<long long, vector<long long> > m;
int main(void) {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  for (cin >> n; i < n; i++) {
    cin >> x;
    if (x == 1 || x == 3) cin >> y;
    if (x == 1) {
      s = y;
      if (m[3].size() == 0)
        continue;
      else {
        while (m[3].size() > 0) {
          if (m[3][m[3].size() - 1] == -1)
            break;
          else if (m[3][m[3].size() - 1] < y)
            ans++, m[3].pop_back();
          else
            break;
        }
      }
    }
    if (x == 2) {
      if (m[4].size() == 0 || m[4][m[4].size() - 1] == 1)
        continue;
      else {
        while (m[4].size() > 0) {
          if (m[4][m[4].size() - 1] == 1)
            break;
          else
            ans++, m[4].pop_back();
        }
      }
    }
    if (x == 4 || x == 6) {
      if (x == 4)
        m[4].push_back(1);
      else
        m[4].push_back(-1);
    }
    if (x == 3 || x == 5) {
      if (x == 3)
        m[3].push_back(y);
      else
        m[3].push_back(-1);
      if (m[3].size() == 0)
        continue;
      else {
        while (m[3].size() > 0) {
          if (m[3][m[3].size() - 1] == -1)
            break;
          else if (m[3][m[3].size() - 1] < s)
            ans++, m[3].pop_back();
          else
            break;
        }
      }
    }
  }
  cout << ans;
  return 0;
}
