#include <bits/stdc++.h>
using namespace std;
string in_name = "sample.in";
string out_name = "sample.out";
ifstream in;
ofstream out;
vector<int> v[1001];
int N;
int how_many(int, int, int);
int main() {
  cin >> N;
  int k, x;
  for (int i = 0; i < N; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> x;
      v[i].push_back(x);
    }
    sort(v[i].begin(), v[i].end());
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < v[i].size() - 1; j++) {
      int before = (i - 1 + N) % N;
      int after = (i + 1) % N;
      if (how_many(i, j, before) != how_many(i, j, after)) res++;
    }
  }
  cout << res << endl;
  return 0;
}
int how_many(int i, int j, int index) {
  int res = 0, up, low;
  up = (int)(upper_bound(v[index].begin(), v[index].end(), v[i][j]) -
             v[index].begin());
  low = (int)(lower_bound(v[index].begin(), v[index].end(), v[i][j + 1]) -
              v[index].begin());
  if (up < v[index].size() && v[index][up] < v[i][j + 1]) res += (low - up) + 1;
  return res;
}
