#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v[2100];
int bSearch(int ind, int val) {
  int ret = -1;
  int s = 0;
  int e = v[ind].size() - 1;
  while (s <= e) {
    int m = (s + e) / 2;
    if (v[ind][m] < val) {
      ret = m;
      s = m + 1;
    } else {
      e = m - 1;
    }
  }
  return ret + 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int l;
      scanf("%d", &l);
      v[i].push_back(l);
    }
    sort(v[i].begin(), v[i].end());
  }
  v[n] = v[0];
  v[n + 1] = v[1];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < v[i].size(); j++) {
      int a = v[i][j - 1];
      int b = v[i][j];
      if (bSearch(i - 1, b) - bSearch(i - 1, a) !=
          bSearch(i + 1, b) - bSearch(i + 1, a))
        ans++;
    }
  }
  printf("%d\n", ans);
}
