#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 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++) {
      std::vector<int>::iterator low, up;
      int before = (i - 1 + N) % N;
      int after = (i + 1) % N;
      int left = 0, right = 0;
      up = upper_bound(v[before].begin(), v[before].end(), v[i][j]);
      low = lower_bound(v[before].begin(), v[before].end(), v[i][j + 1]);
      int u = (int)(up - v[before].begin());
      int l = (int)(low - v[before].begin());
      if (u < v[before].size() && v[before][u] < v[i][j + 1])
        left += (l - u) + 1;
      up = upper_bound(v[after].begin(), v[after].end(), v[i][j]);
      low = lower_bound(v[after].begin(), v[after].end(), v[i][j + 1]);
      u = (int)(up - v[after].begin());
      l = (int)(low - v[after].begin());
      if (u < v[after].size() && v[after][u] < v[i][j + 1])
        right += (l - u) + 1;
      if (left != right) {
        res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}
