#include <bits/stdc++.h>
using namespace std;
vector<int> sec[int(1e3) + 10];
int n, cell;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0, k; i < n; i++) {
    cin >> k;
    for (int j = 0, x; j < k; j++) {
      cin >> x;
      sec[i].push_back(x);
    }
    sort(sec[i].begin(), sec[i].end());
  }
  for (int i = 0; i < n; i++) {
    int prev, next;
    if (i == 0)
      prev = n - 1;
    else
      prev = i - 1;
    if (i == n - 1)
      next = 0;
    else
      next = i + 1;
    int p1 = 0, p2 = 0;
    int cprev = 0, cnext = 0;
    for (int j = 0; j < sec[i].size() - 1; j++) {
      while (sec[prev][p1] < sec[i][j + 1] && p1 < sec[prev].size()) {
        if (sec[prev][p1] > sec[i][j]) cprev++;
        p1++;
      }
      while (sec[next][p2] < sec[i][j + 1] && p2 < sec[next].size()) {
        if (sec[next][p2] > sec[i][j]) cnext++;
        p2++;
      }
      if (cprev != cnext) {
        cell++;
      }
      cprev = 0;
      cnext = 0;
    }
  }
  cout << cell << endl;
  return 0;
}
