#include <bits/stdc++.h>
using namespace std;
const int MaxK = 1003, MaxN = 100005, MaxC = 0x3F3F3F3F, NA = -1;
vector<int> v[MaxK];
int n;
int main(void) {
  int i, j, k, l;
  while (scanf(" %d", &n) != EOF) {
    for (i = 0; i < n; i++) {
      v[i].clear();
      scanf(" %d", &k);
      for (j = 0; j < k; j++) {
        scanf(" %d", &l);
        v[i].push_back(l);
      }
      v[i].push_back(MaxC);
      sort(v[i].begin(), v[i].end());
    }
    int res = 0;
    for (i = 0; i < n; i++) {
      j = (i + n - 1) % n;
      k = (i + 1) % n;
      int p, q, r;
      q = 0;
      r = 0;
      for (p = 0; p < (int)v[i].size() - 1; p++) {
        int balance = 0;
        while (v[j][q] < v[i][p]) q++, balance++;
        while (v[k][r] < v[i][p]) r++, balance--;
        if (p > 0 && balance != 0) res++;
      }
    }
    printf("%d\n", res);
  }
  return 0;
}
