#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
int n, a, ret;
vector<int> w[1010];
int L[100010], R[100010], x[100010];
void Doit(int a1, int a2, int x[]) {
  int j;
  for (j = 0; j < (int)w[a2].size(); j++)
    if (w[a2][j] > w[a1][0]) break;
  for (int i = 1; i < (int)w[a1].size(); i++) {
    x[i] = 0;
    while (j < (int)w[a2].size() && w[a2][j] <= w[a1][i]) {
      x[i]++;
      j++;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    for (int j = 0; j < a; j++) scanf("%d", &x[j]);
    sort(x, x + a);
    for (int j = 0; j < a; j++) w[i].push_back(x[j]);
  }
  ret = 0;
  int tmp;
  for (int i = 1; i <= n; i++) {
    tmp = (i == 1) ? n : i - 1;
    Doit(i, tmp, L);
    tmp = (i == n) ? 1 : i + 1;
    Doit(i, tmp, R);
    for (int j = 1; j < (int)w[i].size(); j++)
      if (L[j] != R[j]) ret++;
  }
  printf("%d\n", ret);
  return 0;
}
