#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> b[1111];
int find(int i, int lo, int hi) {
  return (int)(upper_bound(b[i].begin(), b[i].end(), hi) -
               lower_bound(b[i].begin(), b[i].end(), lo));
}
int main() {
  scanf("%d", &n);
  for (int i = 0, _n = (n); i < _n; i++) {
    scanf("%d", &m);
    b[i].resize(m);
    for (int j = 0, _n = (m); j < _n; j++) scanf("%d", &b[i][j]);
    sort(b[i].begin(), b[i].end());
  }
  int res = 0;
  for (int i = 0, _n = (n); i < _n; i++) {
    for (int j = 0, _n = (b[i].size() - 1); j < _n; j++) {
      int lo = b[i][j], hi = b[i][j + 1];
      int lf = find((i + n - 1) % n, lo, hi);
      int rg = find((i + 1) % n, lo, hi);
      if (lf != rg) {
        res++;
      }
    }
  }
  printf("%d\n", res);
  return 0;
}
