#include <bits/stdc++.h>
using namespace std;
vector<int> v[1010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int p;
      scanf("%d", &p);
      v[i].push_back(p);
    }
  }
  v[n] = v[0];
  v[n + 1] = v[1];
  for (int i = 0; i < n + 2; i++) {
    sort(v[i].begin(), v[i].end());
  }
  int answer = 0;
  for (int i = 1; i < n + 1; i++) {
    int p1 = 0;
    int p2 = 0;
    int m1 = v[i - 1].size();
    int m2 = v[i + 1].size();
    int c1 = 0;
    int c2 = 0;
    for (int j = 0, maxj = v[i].size(); j < maxj; j++) {
      c1 = 0;
      c2 = 0;
      while (p1 < m1 && v[i - 1][p1] < v[i][j]) {
        c1++;
        p1++;
      }
      while (p2 < m2 && v[i + 1][p2] < v[i][j]) {
        c2++;
        p2++;
      }
      if (c1 != c2) {
        if (j != 0) answer++;
      }
    }
  }
  printf("%d\n", answer);
  return 0;
}
