#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long INF64 = (long long)1e18;
const long double eps = 1e-9;
const long double pi = 3.14159265358979323846;
int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int> > vs(n);
  for (int i = 0; i < int(n); ++i) {
    int k;
    scanf("%d", &k);
    vs[i].resize(k);
    for (int j = 0; j < int(k); ++j) scanf("%d", &vs[i][j]);
    sort((vs[i]).begin(), (vs[i]).end());
  }
  int ans = 0;
  for (int i = 0; i < int(n); ++i) {
    for (int j = 0; j < int((int)(vs[i]).size() - 1); ++j) {
      vector<int>::iterator it1 = lower_bound(
          (vs[(i - 1 + n) % n]).begin(), (vs[(i - 1 + n) % n]).end(), vs[i][j]);
      vector<int>::iterator it2 =
          lower_bound((vs[(i - 1 + n) % n]).begin(),
                      (vs[(i - 1 + n) % n]).end(), vs[i][j + 1]);
      int d1 = it2 - it1;
      it1 = lower_bound((vs[(i + 1) % n]).begin(), (vs[(i + 1) % n]).end(),
                        vs[i][j]);
      it2 = lower_bound((vs[(i + 1) % n]).begin(), (vs[(i + 1) % n]).end(),
                        vs[i][j + 1]);
      int d2 = it2 - it1;
      if (d1 != d2) ans++;
    }
  }
  cout << ans;
  return 0;
}
