#include <bits/stdc++.h>
using namespace std;
vector<int> v[1 << 10];
int n;
int bsearch(vector<int> &v, int left, int right, int key) {
  if (v[right] < key) return right + 1;
  if (key < v[left]) return left;
  if (left == right - 1) return right;
  int mid = (left + right) / 2;
  if (key < v[mid])
    return bsearch(v, left, mid, key);
  else
    return bsearch(v, mid, right, key);
}
int cnt(int a, int b, int i) {
  int first = bsearch(v[i], 0, v[i].size() - 1, a);
  int second = bsearch(v[i], 0, v[i].size() - 1, b);
  return (second - first);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    v[i].resize(k);
    for (int j = 0; j < k; j++) cin >> v[i][j];
    sort(v[i].begin(), v[i].end());
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < v[i].size() - 1; j++) {
      int a = v[i][j];
      int b = v[i][j + 1];
      int left = cnt(a, b, (i - 1 + n) % n);
      int right = cnt(a, b, (i + 1) % n);
      if (left != right) res++;
    }
  }
  cout << res << endl;
  return 0;
}
