#include <bits/stdc++.h>
void read(int *a, int n) {
  for (int i = 0; i < n; ++i) a[i] = 0;
  int k, t;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    scanf("%d", &t);
    ++a[t];
  }
}
int numberOfUnstable(int *a, int *b, int *c, int n) {
  int res = 0, k = 0, l = 0;
  bool isfirst = true;
  for (int i = 0; i < n; ++i) {
    if (a[i]) ++k;
    if (c[i]) ++l;
    if (b[i]) {
      if (!isfirst) {
        if (k != l) ++res;
      }
      isfirst = false;
      k = l = 0;
    }
  }
  return res;
}
void copy(int *a, int *b, int n) {
  for (int i = 0; i < n; ++i) a[i] = b[i];
}
int main() {
  int N, m = 100001;
  scanf("%d", &N);
  int *a0 = new int[m], *a1 = new int[m];
  read(a0, m);
  read(a1, m);
  int *b = new int[m], *c = new int[m], *d = new int[m], *t;
  copy(b, a0, m);
  copy(c, a1, m);
  int res = 0;
  for (int i = 2; i < N; ++i) {
    read(d, m);
    res += numberOfUnstable(b, c, d, m);
    t = b;
    b = c;
    c = d;
    d = t;
  }
  res += numberOfUnstable(b, c, a0, m);
  res += numberOfUnstable(c, a0, a1, m);
  printf("%d", res);
  delete a0;
  delete a1;
  delete b;
  delete c;
  delete d;
  return 0;
}
