#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  vector<int> a[1000], u;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &m);
    while (m--) {
      scanf("%d", &x);
      u.push_back(x);
      a[i].push_back(x);
    }
    sort(a[i].begin(), a[i].end());
  }
  sort(u.begin(), u.end());
  for (int i = 0; i < n; i++)
    for (int& x : a[i]) x = lower_bound(u.begin(), u.end(), x) - u.begin();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int p = (i + n - 1) % n, q = (i + 1) % n;
    for (size_t j = 0; j + 1 < a[i].size(); j++) {
      int lo = a[i][j], hi = a[i][j + 1];
      auto plo = upper_bound(a[p].begin(), a[p].end(), lo);
      auto phi = lower_bound(a[p].begin(), a[p].end(), hi);
      auto qlo = upper_bound(a[q].begin(), a[q].end(), lo);
      auto qhi = lower_bound(a[q].begin(), a[q].end(), hi);
      if (phi - plo != qhi - qlo) ans++;
    }
  }
  printf("%d\n", ans);
}
