#include <bits/stdc++.h>
using namespace std;
const int maxN = 1005;
vector<int> f[maxN];
int n;
vector<int> left_count[maxN];
vector<int> right_count[maxN];
void readFile() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int k, tmp;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &tmp);
      f[i].push_back(tmp);
    }
  }
}
int main() {
  readFile();
  for (int i = 0; i < n; i++) sort(f[i].begin(), f[i].end());
  int count = 0;
  for (int i = 0; i < n; i++) {
    int left = (i == 0) ? (n - 1) : (i - 1);
    int right = (i == n - 1) ? 0 : (i + 1);
    int left_index = 0;
    int right_index = 0;
    for (int j = 1; j < f[i].size(); j++) {
      int left_count = 0;
      int right_count = 0;
      while (left_index < f[left].size() && f[left][left_index] < f[i][j]) {
        if (f[left][left_index] > f[i][j - 1] && f[left][left_index] < f[i][j])
          left_count++;
        left_index++;
      }
      while (right_index < f[right].size() && f[right][right_index] < f[i][j]) {
        if (f[right][right_index] > f[i][j - 1] &&
            f[right][right_index] < f[i][j])
          right_count++;
        right_index++;
      }
      if (left_count != right_count) count++;
    }
  }
  cout << count << endl;
}
