#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, x, y, cnt = 0, xx, yy;
  cin >> n;
  vector<long long> a[n];
  for (i = 0; i < n; i++) {
    cin >> x;
    a[i].resize(x);
    for (j = 0; j < x; j++) {
      cin >> a[i][j];
    }
    sort(a[i].begin(), a[i].end());
  }
  for (i = 0; i < n; i++) {
    x = (i - 1 + n) % n;
    y = (i + 1) % n;
    xx = 0;
    yy = 0;
    long long x1, y1;
    for (j = 0; j + 1 < a[i].size(); j++) {
      while (a[x][xx] < a[i][j] && xx < a[x].size()) {
        xx++;
      }
      x1 = xx;
      while (a[y][yy] < a[i][j] && yy < a[y].size()) {
        yy++;
      }
      y1 = yy;
      while (a[x][xx] <= a[i][j + 1] && xx < a[x].size()) {
        xx++;
      }
      while (a[y][yy] < a[i][j + 1] && yy < a[y].size()) {
        yy++;
      }
      if (xx - x1 != yy - y1) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}
