#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
using namespace std;
long double EPS = 1e-7;
vector<int> a[1000];
int mget(int d, int u, int n) {
  if (a[n][0] > u) return 0;
  if (a[n][a[n].size() - 1] < d) return 0;
  int l = -1, r = a[n].size();
  while (r - l > 1) {
    int m = (r + l) / 2;
    if (a[n][m] >= d)
      r = m;
    else
      l = m;
  }
  int L = r;
  l = 0, r = a[n].size();
  while (r - l > 1) {
    int m = (r + l) / 2;
    if (a[n][m] <= u)
      l = m;
    else
      r = m;
  }
  int R = l;
  return R - L + 1;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int m;
    scanf("%d", &m);
    for (int j = 0; j < m; j++) {
      int x;
      scanf("%d", &x);
      a[i].push_back(x);
    }
    sort(a[i].begin(), a[i].end());
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    int p1 = i - 1, p2 = i + 1;
    if (p1 < 0) p1 = n - 1;
    if (p2 >= n) p2 = 0;
    for (int j = 0; j < a[i].size() - 1; j++) {
      if (mget(a[i][j], a[i][j + 1], p1) != mget(a[i][j], a[i][j + 1], p2))
        res++;
    }
  }
  cout << res << endl;
}
