#include <bits/stdc++.h>
using namespace std;
long long func(int lt[], int cur[], int rt[]) {
  long long res = 0;
  int l = 1, r = 1, idx = 1, lsum, rsum;
  while (idx <= cur[0]) {
    lsum = rsum = 0;
    while (l <= lt[0] && lt[l] < cur[idx]) ++l, ++lsum;
    while (r <= rt[0] && rt[r] < cur[idx]) ++r, ++rsum;
    if (idx > 1 && lsum != rsum) ++res;
    ++idx;
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  int fr[100001], se[100001];
  int lt[100001], cur[100001], rt[100001];
  cin >> fr[0];
  for (int i = 1; i <= fr[0]; ++i) cin >> fr[i];
  sort(fr + 1, fr + fr[0] + 1);
  cin >> se[0];
  for (int i = 1; i <= se[0]; ++i) cin >> se[i];
  sort(se + 1, se + se[0] + 1);
  for (int i = 0; i <= fr[0]; ++i) lt[i] = fr[i];
  for (int i = 0; i <= se[0]; ++i) cur[i] = se[i];
  long long ans = 0;
  for (int i = 2; i < n; ++i) {
    cin >> rt[0];
    for (int j = 1; j <= rt[0]; ++j) cin >> rt[j];
    sort(rt + 1, rt + rt[0] + 1);
    ans += func(lt, cur, rt);
    for (int j = 0; j <= cur[0]; ++j) lt[j] = cur[j];
    for (int j = 0; j <= rt[0]; ++j) cur[j] = rt[j];
  }
  ans += func(lt, cur, fr);
  ans += func(cur, fr, se);
  cout << ans << endl;
  return 0;
}
