#include <bits/stdc++.h>
using namespace std;
vector<int> v[1010];
vector<int>::iterator it1, it2, it3, it4;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      v[i].push_back(a);
    }
    sort(v[i].begin(), v[i].end());
  }
  long long counter = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v[i].size() - 1; j++) {
      int d1 = 0, d2 = 0;
      int up = i - 1;
      int down = i + 1;
      if (i == 1) {
        up = n;
        down = 2;
      }
      if (i == n) {
        up = n - 1;
        down = 1;
      }
      int left = v[i][j];
      int right = v[i][j + 1];
      it1 = upper_bound(v[down].begin(), v[down].end(), left);
      it2 = lower_bound(v[down].begin(), v[down].end(), right);
      int f1 = it1 - v[down].begin();
      int f2 = it2 - v[down].begin() - 1;
      if (v[down][f1] > right)
        d1 = 0;
      else {
        d1 = f2 - f1 + 1;
      }
      it3 = upper_bound(v[up].begin(), v[up].end(), left);
      it4 = lower_bound(v[up].begin(), v[up].end(), right);
      int f3 = it3 - v[up].begin();
      int f4 = it4 - v[up].begin() - 1;
      if (v[up][f3] > right)
        d2 = 0;
      else {
        d2 = f4 - f3 + 1;
      }
      if (d1 != d2) counter++;
    }
  }
  cout << counter;
}
