#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
vector<int> dist[MAXN + 5];
int ns[MAXN + 5];
int n;
int main() {
  FILE *in = stdin;
  int c, c2;
  fscanf(in, "%d", &n);
  for (c = 0; c < n; c++) {
    fscanf(in, "%d", &ns[c]);
    dist[c].resize(ns[c]);
    for (c2 = 0; c2 < ns[c]; c2++) fscanf(in, "%d", &dist[c][c2]);
    sort(dist[c].begin(), dist[c].end());
  }
  int ret = 0;
  for (c = 0; c < n; c++) {
    int up = (c - 1 + n) % n;
    int down = (c + 1) % n;
    int i1 = 0;
    int i2 = 0;
    for (c2 = 0; c2 + 1 < ns[c]; c2++) {
      int ret1 = 0, ret2 = 0;
      while (i1 < ns[up] && dist[up][i1] <= dist[c][c2 + 1]) {
        ret1 += dist[up][i1] >= dist[c][c2];
        i1++;
      }
      while (i2 < ns[down] && dist[down][i2] <= dist[c][c2 + 1]) {
        ret2 += dist[down][i2] >= dist[c][c2];
        i2++;
      }
      if (ret1 != ret2) {
        ret++;
      }
    }
  }
  printf("%d\n", ret);
  return 0;
}
