#include <bits/stdc++.h>
using namespace std;
const int maxN = 1 << 17;
set<int> a[maxN];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    while (k--) {
      int x;
      cin >> x;
      a[i].insert(x);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    vector<int> L =
        vector<int>((a[(i + n - 1) % n]).begin(), (a[(i + n - 1) % n]).end());
    vector<int> R =
        vector<int>((a[(i + 1) % n]).begin(), (a[(i + 1) % n]).end());
    int last = -1;
    for (auto x : a[i]) {
      if (last == -1) {
        last = x;
        continue;
      }
      int cl = lower_bound((L).begin(), (L).end(), x) -
               lower_bound((L).begin(), (L).end(), last);
      int cr = lower_bound((R).begin(), (R).end(), x) -
               lower_bound((R).begin(), (R).end(), last);
      ans += (cl != cr);
      last = x;
    }
  }
  cout << ans << endl;
  return 0;
}
