#include <bits/stdc++.h>
using namespace std;
const int M = 100000 + 10;
const double eps = 1e-9;
int k[M];
vector<int> p[M];
int cnt1[M];
int cnt2[M];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int x;
      cin >> x;
      p[i].push_back(x);
    }
    sort(p[i].begin(), p[i].end());
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    int pre = (i - 1 + n) % n;
    int next = (i + 1) % n;
    for (int j = 0; j <= k[i]; j++) {
      cnt1[j] = 0;
      cnt2[j] = 0;
    }
    for (int j = 0; j < p[pre].size(); j++) {
      int val = p[pre][j];
      int pos = lower_bound(p[i].begin(), p[i].end(), val) - p[i].begin();
      cnt1[pos]++;
    }
    for (int j = 0; j < p[next].size(); j++) {
      int val = p[next][j];
      int pos = lower_bound(p[i].begin(), p[i].end(), val) - p[i].begin();
      cnt2[pos]++;
    }
    for (int j = 1; j < k[i]; j++) {
      int res = (cnt1[j] == cnt2[j] ? 0 : 1);
      ans = ans + res;
    }
  }
  cout << ans << endl;
  return 0;
}
