#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > a;
vector<int> k;
int findlb(int s, int ll) {
  int l = 0;
  int r = k[s] - 1;
  while (r - l > 1) {
    int t = (r + l) / 2;
    if (a[s][t] < ll) l = t;
    if (a[s][t] > ll) r = t;
  }
  if (a[s][l] > ll) return l;
  return r;
}
int has(int s, int ll, int rr) {
  int l = findlb(s, ll);
  int r = findlb(s, rr);
  if ((a[s][r] < ll) || (a[s][r] > rr)) r = r - 1;
  if (r < l) return 0;
  if ((a[s][l] < ll) || (a[s][l] > rr)) return 0;
  if ((a[s][r] < ll) || (a[s][r] > rr)) return 0;
  return (r - l + 1);
}
int main() {
  int n;
  cin >> n;
  a.resize(n);
  k.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> k[i];
    a[i].resize(k[i]);
    for (int j = 0; j < k[i]; ++j) {
      cin >> a[i][j];
    }
    sort(a[i].begin(), a[i].end());
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int pred = (i + n - 1) % n;
    int sled = (i + 1) % n;
    for (int j = 0; j < k[i] - 1; ++j) {
      int l = a[i][j];
      int r = a[i][j + 1];
      int h1 = has(pred, l, r);
      int h2 = has(sled, l, r);
      if (h1 != h2) {
        res += 1;
      }
    }
  }
  cout << res << endl;
  return 0;
}
