#include <bits/stdc++.h>
using namespace std;
int res;
int n, m;
vector<vector<int> > mas;
void check(vector<int> &prv, vector<int> &cur, vector<int> &nxt) {
  for (int i = 0; i < cur.size() - 1; ++i) {
    int beg = cur[i];
    int end = cur[i + 1];
    int cnt_prv = upper_bound(prv.begin(), prv.end(), end) -
                  lower_bound(prv.begin(), prv.end(), beg);
    int cnt_nxt = upper_bound(nxt.begin(), nxt.end(), end) -
                  lower_bound(nxt.begin(), nxt.end(), beg);
    if (cnt_prv != cnt_nxt) res++;
  }
}
int main() {
  scanf("%d", &n);
  mas.resize(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &m);
    mas[i].resize(m);
    for (int j = 0; j < m; ++j) {
      scanf("%d", &mas[i][j]);
    }
    sort(mas[i].begin(), mas[i].end());
  }
  for (int i = 0; i < n; ++i) {
    check(mas[i], mas[(i + 1) % n], mas[(i + 2) % n]);
  }
  cout << res;
  return 0;
}
