#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
vector<int> v[maxn];
int c[maxn * 100];
int l[maxn * 100], r[maxn * 100];
int n;
int lowbit(int x) { return x & (-x); }
void add(int x) {
  while (x <= 100000) {
    c[x] += 1;
    x += lowbit(x);
  }
}
int sum(int x) {
  int ans = 0;
  while (x >= 1) {
    ans += c[x];
    x -= lowbit(x);
  }
  return ans;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) v[i].clear();
    for (int i = 1; i <= n; i++) {
      int num;
      scanf("%d", &num);
      while (num--) {
        int x;
        scanf("%d", &x);
        v[i].push_back(x);
      }
    }
    for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if ((int)v[i].size() == 1) continue;
      int a, b;
      if (i == n)
        a = 1;
      else
        a = i + 1;
      if (i == 1)
        b = n;
      else
        b = i - 1;
      memset(c, 0, sizeof(c));
      for (int j = 0; j < (int)v[a].size(); j++) add(v[a][j]);
      for (int j = 1; j < (int)v[i].size(); j++) {
        int ll = v[i][j - 1], rr = v[i][j];
        l[j] = sum(rr) - sum(ll - 1);
      }
      memset(c, 0, sizeof(c));
      for (int j = 0; j < (int)v[b].size(); j++) add(v[b][j]);
      for (int j = 1; j < (int)v[i].size(); j++) {
        int ll = v[i][j - 1], rr = v[i][j];
        r[j] = sum(rr) - sum(ll - 1);
      }
      for (int j = 1; j < (int)v[i].size(); j++) {
        if (l[j] != r[j]) ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
