#include <bits/stdc++.h>
using namespace std;
vector<int> v[1010];
int N, K, tmp;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> K;
    for (int j = 0; j < K; j++) {
      cin >> tmp;
      v[i].push_back(tmp);
    }
    sort(v[i].begin(), v[i].end());
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int l = (i + N - 1) % N;
    int r = (i + 1) % N;
    vector<int>::iterator ll = lower_bound(v[l].begin(), v[l].end(), v[i][0]);
    vector<int>::iterator lr = lower_bound(v[r].begin(), v[r].end(), v[i][0]);
    vector<int>::iterator tr, tl;
    for (int j = 1; j < v[i].size(); j++) {
      tl = lower_bound(ll, v[l].end(), v[i][j]);
      tr = lower_bound(lr, v[r].end(), v[i][j]);
      if (tl - ll != tr - lr) ans++;
      ll = tl;
      lr = tr;
    }
  }
  cout << ans << endl;
  return 0;
}
