#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 9;
vector<vector<int>> v;
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    v.push_back({0});
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      v.back().push_back(x);
    }
    sort(v.back().begin(), v.back().end());
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int h = 1; h + 1 < v[i].size(); h++) {
      pair<int, int> j = make_pair(v[i][h], v[i][(h + 1) % v[i].size()]);
      int fOnFirst = upper_bound(v[(i - 1 + n) % n].begin(),
                                 v[(i - 1 + n) % n].end(), j.first) -
                     v[(i - 1 + n) % n].begin();
      int sOnFirst = upper_bound(v[(i - 1 + n) % n].begin(),
                                 v[(i - 1 + n) % n].end(), j.second) -
                     v[(i - 1 + n) % n].begin();
      int fOnSecond =
          upper_bound(v[(i + 1) % n].begin(), v[(i + 1) % n].end(), j.first) -
          v[(i + 1) % n].begin();
      int sOnSecond =
          upper_bound(v[(i + 1) % n].begin(), v[(i + 1) % n].end(), j.second) -
          v[(i + 1) % n].begin();
      if (sOnFirst - fOnFirst != sOnSecond - fOnSecond) ans++;
    }
  }
  printf("%d", ans);
  return 0;
}
