#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1000 + 5;
int n, ans;
vector<int> sec[Maxn], thr[Maxn];
int main() {
  scanf("%d", &n);
  int k, a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &a);
      sec[i].push_back(a);
      thr[i].push_back(a);
      thr[(i + 1) % n].push_back(a);
    }
  }
  for (int i = 0; i < n; i++) {
    sort(sec[i].begin(), sec[i].end());
    sort(thr[i].begin(), thr[i].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (int)sec[i].size() - 1; j++) {
      int ind1 = lower_bound(thr[i].begin(), thr[i].end(), sec[i][j]) -
                 thr[i].begin(),
          ind2 = lower_bound(thr[i].begin(), thr[i].end(), sec[i][j + 1]) -
                 thr[i].begin();
      int ind3 = lower_bound(thr[(i + 1) % n].begin(), thr[(i + 1) % n].end(),
                             sec[i][j]) -
                 thr[(i + 1) % n].begin(),
          ind4 = lower_bound(thr[(i + 1) % n].begin(), thr[(i + 1) % n].end(),
                             sec[i][j + 1]) -
                 thr[(i + 1) % n].begin();
      if (ind4 - ind3 != ind2 - ind1) ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
