#include <bits/stdc++.h>
using namespace std;
const int nMax = 100100;
vector<int> e[nMax];
int n, k[2], t[2];
int S(int i, int j) {
  return lower_bound(e[i].begin(), e[i].end(), j) - e[i].begin();
};
int main() {
  int i, j, m, size, ans, u;
  while (scanf("%d", &n) != EOF) {
    ans = 0;
    for (i = 0; i < n; i++) e[i].clear();
    for (i = 0; i < n; i++) {
      scanf("%d", &m);
      while (m--) {
        scanf("%d", &u);
        e[i].push_back(u);
      }
      sort(e[i].begin(), e[i].end());
    }
    for (i = 0; i < n; i++) {
      k[0] = (i - 1 + n) % n;
      k[1] = (i + 1) % n;
      for (j = 1, size = e[i].size(); j < size; j++) {
        t[0] = S(k[0], e[i][j]) - S(k[0], e[i][j - 1]);
        t[1] = S(k[1], e[i][j]) - S(k[1], e[i][j - 1]);
        if (t[0] != t[1]) ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
