#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v[1010];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int aux, aux2;
    scanf("%d", &aux);
    for (int j = 0; j < aux; ++j) {
      scanf("%d", &aux2);
      v[i].push_back(aux2);
    }
    sort(v[i].begin(), v[i].end());
  }
  int r = 0;
  for (int i = 0; i < n; ++i) {
    int pnt1 = 0, pnt2 = 0;
    int pr = (i - 1 + n) % n, ne = (i + 1) % n;
    for (int j = 0; j < v[i].size() - 1; ++j) {
      int q1 = 0, q2 = 0;
      while (pnt1 < v[pr].size() && v[pr][pnt1] < v[i][j]) pnt1++;
      while (pnt1 < v[pr].size() && v[pr][pnt1] < v[i][j + 1]) pnt1++, q1++;
      while (pnt2 < v[ne].size() && v[ne][pnt2] < v[i][j]) pnt2++;
      while (pnt2 < v[ne].size() && v[ne][pnt2] < v[i][j + 1]) pnt2++, q2++;
      if (q1 != q2) r++;
    }
  }
  printf("%d\n", r);
  return 0;
}
