#include <bits/stdc++.h>
using namespace std;
int a[1000000][2], b[1000000];
int n, ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i][0]);
    if (a[i][0] == 1 || a[i][0] == 3) scanf("%d", &a[i][1]);
  }
  int v = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i][0] == 1)
      v = a[i][1];
    else if (a[i][0] == 3)
      b[++b[0]] = a[i][1];
    else if (a[i][0] == 5)
      b[0] = 0;
    while (b[0] && b[b[0]] < v) b[0]--, ans++;
  }
  v = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i][0] == 2)
      ans += v, v = 0;
    else if (a[i][0] == 6)
      v++;
    else if (a[i][0] == 4)
      v = 0;
  }
  cout << ans;
  return 0;
}
