#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic warning "-Wall"
int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int> > sec(n);
  for (typeof(n) i = (0); i < (n); i++) {
    int k;
    scanf("%d", &k);
    sec[i].resize(k);
    for (typeof(k) j = (0); j < (k); j++) scanf("%d", &sec[i][j]);
    sort((sec[i]).begin(), (sec[i]).end());
  }
  int count = 0;
  for (typeof(n) i = (0); i < (n); i++) {
    int k = int(sec[i].size());
    if (not k) continue;
    int lasth = sec[i][0];
    ;
    int l = (i - 1 + n) % n;
    int r = (i + 1) % n;
    for (typeof(k) j = (1); j < (k); j++) {
      int nl = lower_bound((sec[l]).begin(), (sec[l]).end(), sec[i][j]) -
               lower_bound((sec[l]).begin(), (sec[l]).end(), lasth);
      int nr = lower_bound((sec[r]).begin(), (sec[r]).end(), sec[i][j]) -
               lower_bound((sec[r]).begin(), (sec[r]).end(), lasth);
      if (nl != nr) count++;
      lasth = sec[i][j];
    }
  }
  printf("%d\n", count);
}
