#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int> > v(n);
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int tmp;
      scanf("%d", &tmp);
      v[i].push_back(tmp);
    }
    sort(v[i].begin(), v[i].end());
  }
  vector<vector<int> > on_right_side(n);
  vector<vector<int> > on_left_side(n);
  for (int i = 0; i < n; i++) {
    int current_sector = i;
    int next_sector = (i + 1) % n;
    if (v[current_sector].size() < 2) {
      continue;
    }
    int line_idx = 1;
    int ptr = 0;
    while (line_idx < v[current_sector].size()) {
      int now = 0;
      while (ptr < v[next_sector].size() &&
             v[next_sector][ptr] <= v[current_sector][line_idx]) {
        if (v[current_sector][line_idx - 1] <= v[next_sector][ptr] &&
            v[next_sector][ptr] <= v[current_sector][line_idx]) {
          now++;
        }
        ptr++;
      }
      on_right_side[current_sector].push_back(now);
      line_idx++;
    }
  }
  for (int i = 0; i < n; i++) {
    int current_sector = i;
    int next_sector = (i - 1 + 5 * n) % n;
    if (v[current_sector].size() < 2) {
      continue;
    }
    int line_idx = 1;
    int ptr = 0;
    while (line_idx < v[current_sector].size()) {
      int now = 0;
      while (ptr < v[next_sector].size() &&
             v[next_sector][ptr] <= v[current_sector][line_idx]) {
        if (v[current_sector][line_idx - 1] <= v[next_sector][ptr] &&
            v[next_sector][ptr] <= v[current_sector][line_idx]) {
          now++;
        }
        ptr++;
      }
      on_left_side[current_sector].push_back(now);
      line_idx++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < on_left_side[i].size(); j++) {
      if (on_left_side[i][j] != on_right_side[i][j]) {
        ans++;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
