#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
vector<int> arr[MAXN];
int ans;
int main() {
  int n, sz, x, i, j, u, l, a, b, l1, r1, l2, r2;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d", &sz);
    for (j = 1; j <= sz; ++j) {
      scanf("%d", &x);
      arr[i].push_back(x);
    }
    sort(arr[i].begin(), arr[i].end());
  }
  for (i = 0; i < n; ++i) {
    u = (i - 1 >= 0 ? (i - 1) : n - 1), l = (i + 1 < n ? (i + 1) : 0);
    for (j = 0; j < arr[i].size() - 1; ++j) {
      a = arr[i][j];
      b = arr[i][j + 1];
      l1 = upper_bound(arr[u].begin(), arr[u].end(), a) - arr[u].begin();
      l2 = upper_bound(arr[l].begin(), arr[l].end(), a) - arr[l].begin();
      r1 = lower_bound(arr[u].begin(), arr[u].end(), b) - arr[u].begin();
      r2 = lower_bound(arr[l].begin(), arr[l].end(), b) - arr[l].begin();
      if (r2 - l2 != r1 - l1) ans++;
    }
  }
  printf("%d", ans);
  return 0;
}
