#include <bits/stdc++.h>
long i, j, k, l, n, la, lc, ans;
long a[200000], b[10][200000], c[200000];
void find(long z) {
  long i, j = (z + 1) % 3, k = (z + 2) % 3;
  long x, y, x2, y2;
  x = 1;
  y = 1;
  for (i = 1; i <= b[z][0] && (x <= b[j][0] || y <= b[k][0]); ++i) {
    while (x <= b[j][0] && b[j][x] < b[z][i]) ++x;
    while (y <= b[k][0] && b[k][y] < b[z][i]) ++y;
    if (i != 1 && x - x2 != y - y2) ++ans;
    x2 = x;
    y2 = y;
  }
  return;
}
int main() {
  scanf("%ld", &n);
  scanf("%ld", &la);
  for (i = 1; i <= la; ++i) {
    scanf("%ld", &a[i]);
  }
  scanf("%ld", &lc);
  for (i = 1; i <= lc; ++i) {
    scanf("%ld", &c[i]);
  }
  std::sort(a + 1, a + la + 1);
  std::sort(c + 1, c + lc + 1);
  b[1][0] = la;
  for (i = 1; i <= la; ++i) {
    b[1][i] = a[i];
  }
  b[2][0] = lc;
  for (i = 1; i <= lc; ++i) {
    b[2][i] = c[i];
  }
  ans = 0;
  for (i = 3; i <= n; ++i) {
    j = i % 3;
    scanf("%ld", &b[j][0]);
    for (k = 1; k <= b[j][0]; ++k) {
      scanf("%ld", &b[j][k]);
    }
    std::sort(b[j] + 1, b[j] + b[j][0] + 1);
    find((i - 1) % 3);
  }
  j = n % 3;
  k = (j + 1) % 3;
  b[k][0] = la;
  for (i = 1; i <= la; ++i) {
    b[k][i] = a[i];
  }
  find(j);
  j = (k + 1) % 3;
  b[j][0] = lc;
  for (i = 1; i <= lc; ++i) {
    b[j][i] = c[i];
  }
  find(k);
  printf("%ld\n", ans);
  return 0;
}
