#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > web;
vector<int> tmp;
int getBoundries(vector<int> V, int a, int);
int main() {
  int n;
  cin >> n;
  web.resize(n);
  int ki;
  int pj;
  for (int i = 0; i < int(n); i++) {
    tmp.clear();
    cin >> ki;
    for (int j = 0; j < int(ki); j++) {
      cin >> pj;
      tmp.push_back(pj);
    }
    sort((tmp).begin(), (tmp).end());
    web[i] = tmp;
  }
  long long ans = 0LL;
  for (int i = 0; i < int(n); i++) {
    int UP = i + 1;
    int DOWN = i - 1;
    if (UP == n) UP = 0;
    if (DOWN == -1) DOWN = n - 1;
    for (int j = 1; j < int(web[i].size()); j++) {
      vector<int>::iterator begU =
          lower_bound((web[UP]).begin(), (web[UP]).end(), web[i][j - 1]);
      vector<int>::iterator begD =
          lower_bound((web[DOWN]).begin(), (web[DOWN]).end(), web[i][j - 1]);
      vector<int>::iterator endU =
          lower_bound((web[UP]).begin(), (web[UP]).end(), web[i][j]);
      vector<int>::iterator endD =
          lower_bound((web[DOWN]).begin(), (web[DOWN]).end(), web[i][j]);
      if (endU - begU != endD - begD) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
int getBoundries(vector<int> V, int a, int i) {
  int j = V.size();
  int k;
  if (V[j - 1] < a)
    return j;
  else if (a < V[i])
    return i;
  else {
    while (j - i > 1) {
      k = (i + j) / 2;
      if (V[k] < a) {
        i = k;
      } else {
        j = k;
      }
    }
    return j;
  }
}
