#include <bits/stdc++.h>
using namespace std;
void precompute(void) {}
int main() {
  int n, i, j, size[1024];
  vector<vector<int> > bri;
  precompute();
  while (scanf("%d", &n) != EOF) {
    bri.clear();
    bri.push_back(vector<int>());
    bri.push_back(vector<int>());
    for (i = 1; i <= n; i++) {
      scanf("%d", &size[i]);
      bri.push_back(vector<int>());
      bri[i].resize(size[i]);
      for (j = 0; j < size[i]; j++) {
        scanf("%d", &bri[i][j]);
      }
      sort(bri[i].begin(), bri[i].end());
    }
    bri[0] = bri[n];
    bri[n + 1] = bri[1];
    int lo, hi, ri, le, ans = 0;
    for (i = 1; i <= n; i++) {
      for (j = 1; j < size[i]; j++) {
        lo = bri[i][j - 1];
        hi = bri[i][j];
        le = upper_bound(bri[i + 1].begin(), bri[i + 1].end(), hi) -
             upper_bound(bri[i + 1].begin(), bri[i + 1].end(), lo);
        ri = upper_bound(bri[i - 1].begin(), bri[i - 1].end(), hi) -
             upper_bound(bri[i - 1].begin(), bri[i - 1].end(), lo);
        if (le != ri) {
          ans++;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
