#include <bits/stdc++.h>
using namespace std;
int *h;
void qs(int q, int w) {
  int e = q, r = w, t = h[q + (rand() % (w - q + 1))], y;
  do {
    while (h[e] < t) e++;
    while (h[r] > t) r--;
    if (e <= r) {
      y = h[e];
      h[e] = h[r];
      h[r] = y;
      e++;
      r--;
    }
  } while (e <= r);
  if (q < r) qs(q, r);
  if (e < w) qs(e, w);
}
int main() {
  int q, w, e, r, t = 0, c, w1, c1, v1, v, *a[100000], s[100000];
  cin >> q;
  for (w = 0; w < q; w++) {
    scanf("%d", &s[w]);
    a[w] = new int[s[w]];
    for (e = 0; e < s[w]; e++) scanf("%d", &a[w][e]);
    h = a[w];
    qs(0, s[w] - 1);
  }
  for (w = 0; w < q; w++) {
    c = (w - 1 + q) % q;
    v = (w + 1) % q;
    c1 = w1 = v1 = 0;
    while ((c1 < s[c]) && (a[c][c1] < a[w][w1])) c1++;
    while ((v1 < s[v]) && (a[v][v1] < a[w][w1])) v1++;
    for (w1++; w1 < s[w]; w1++) {
      e = 0;
      while ((c1 < s[c]) && (a[c][c1] < a[w][w1])) {
        c1++;
        e++;
      }
      while ((v1 < s[v]) && (a[v][v1] < a[w][w1])) {
        v1++;
        e--;
      }
      if (e != 0) t++;
    }
  }
  cout << t;
  return 0;
}
