#include <bits/stdc++.h>
using namespace std;
istream &in = cin;
int n;
vector<int> brg[1001];
int main() {
  in >> n;
  for (int i = 0; i < n; ++i) {
    int k;
    in >> k;
    for (int j = 0; j < k; ++j) {
      int b;
      in >> b;
      brg[i].push_back(b);
    }
    sort(brg[i].begin(), brg[i].end());
  }
  int s1, s2, s3;
  int ret = 0;
  for (int go = 0; go < n; ++go) {
    s1 = (go - 1 + n) % n;
    s2 = go;
    s3 = (go + 1 + n) % n;
    int i, l_idx, r_idx;
    for (l_idx = 0; l_idx < brg[s1].size() && brg[s1][l_idx] < brg[s2][0];
         ++l_idx) {
    }
    for (r_idx = 0; r_idx < brg[s3].size() && brg[s3][r_idx] < brg[s2][0];
         ++r_idx) {
    }
    for (i = 0; i < brg[s2].size() - 1; ++i) {
      int l_count = 0, r_count = 0;
      for (; l_idx < brg[s1].size() && brg[s1][l_idx] < brg[s2][i + 1]; ++l_idx)
        ++l_count;
      for (; r_idx < brg[s3].size() && brg[s3][r_idx] < brg[s2][i + 1]; ++r_idx)
        ++r_count;
      if (l_count != r_count) ++ret;
    }
    if (s2 == n - 1) break;
  }
  cout << ret << endl;
  return 0;
}
