#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int mod = 1000000007;
const int INF = 1000000;
const int N = 10005;
using namespace std;
vector<int> a[1100];
int n, x, k, i1, i2, i3, c1, c2;
int ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> k;
    for (int j = 0; j < k; ++j) {
      scanf("%d", &x);
      a[i].push_back(x);
    }
    sort(a[i].begin(), a[i].end());
  }
  a[n] = a[0];
  a[n + 1] = a[1];
  for (int i = 1; i <= n; ++i) {
    i1 = 0;
    i3 = 0;
    while ((i1 < (int)a[i - 1].size()) && (a[i - 1][i1] < a[i][0])) ++i1;
    while ((i3 < (int)a[i + 1].size()) && (a[i + 1][i3] < a[i][0])) ++i3;
    for (int j = 1; j < (int)a[i].size(); ++j) {
      c1 = 0;
      c2 = 0;
      while ((i1 < (int)a[i - 1].size()) && (a[i - 1][i1] < a[i][j])) {
        i1++;
        c1++;
      }
      while ((i3 < (int)a[i + 1].size()) && (a[i + 1][i3] < a[i][j])) {
        i3++;
        c2++;
      }
      ans += (c1 != c2);
    }
  }
  printf("%d\n", ans);
}
