#include <bits/stdc++.h>
using namespace std;
int cc[5000];
int *prev1, *cur1, *next1;
int first[100100];
int second[100100];
int last[100100];
int k1, k2, k3;
int cnt(int *pr, int *cur, int *nxt, int k1, int k2, int k3) {
  int i = 0, j = 0, c1, c2;
  int rs = 0;
  for (int k = 0; k < k2 - 1; k++) {
    c1 = c2 = 0;
    for (; pr[i] < cur[k + 1] && i < k1; i++) c1 += pr[i] > cur[k];
    for (; nxt[j] < cur[k + 1] && j < k3; j++) c2 += nxt[j] > cur[k];
    if (c1 != c2) rs++;
  }
  return rs;
}
int main() {
  prev1 = new int[100100];
  cur1 = new int[100100];
  next1 = new int[100100];
  int n;
  cin >> n;
  int kf, ks, kl;
  cin >> kf;
  for (int i = 0; i < kf; i++) {
    cin >> first[i];
    prev1[i] = first[i];
  }
  sort(first, first + kf);
  sort(prev1, prev1 + kf);
  k1 = kf;
  cin >> ks;
  k2 = ks;
  for (int i = 0; i < ks; i++) {
    cin >> second[i];
    cur1[i] = second[i];
  }
  sort(second, second + ks);
  sort(cur1, cur1 + ks);
  int res = 0;
  for (int i = 1; i < n - 1; i++) {
    cin >> k3;
    for (int j = 0; j < k3; j++) cin >> next1[j];
    sort(next1, next1 + k3);
    res += cnt(prev1, cur1, next1, k1, k2, k3);
    swap(prev1, cur1);
    swap(next1, cur1);
    swap(k1, k2);
    swap(k2, k3);
  }
  kl = k2;
  for (int i = 0; i < kl; i++) last[i] = cur1[i];
  res += cnt(last, first, second, kl, kf, ks);
  res += cnt(prev1, last, first, k1, kl, kf);
  cout << res;
}
