#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
vector<int> line[MAXN];
int n;
void readData() {
  int tmp;
  int k;
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    scanf("%d", &k);
    for (int j = 0; j < (k); ++j) {
      scanf("%d", &tmp);
      line[i].push_back(tmp);
    }
    sort(line[i].begin(), line[i].end());
  }
}
int daj(int xx, int yy, const vector<int> &v) {
  int l = 0, p = v.size() - 1;
  if (xx > v[p]) return 0;
  if (yy < v[l]) return 0;
  while (l < p) {
    int t = (l + p) / 2;
    if (v[t] < xx) {
      l = t + 1;
    } else {
      p = t;
    }
  }
  int fir = l;
  l = 0;
  p = v.size() - 1;
  while (l < p) {
    int t = (l + p + 1) / 2;
    if (v[t] > yy) {
      p = t - 1;
    } else {
      l = t;
    }
  }
  return p - fir + 1;
}
int main() {
  readData();
  int res = 0;
  int l, p;
  for (int i = 0; i < (n); ++i) {
    l = (i + (n - 1)) % n;
    p = (i + 1) % n;
    for (int j = 1; j <= ((int)line[i].size() - 1); ++j) {
      if (daj(line[i][j - 1], line[i][j], line[l]) !=
          daj(line[i][j - 1], line[i][j], line[p])) {
        res++;
      }
    }
  }
  printf("%d\n", res);
}
