#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v[1001];
  int n, k, r;
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) {
      v[i].clear();
      scanf("%d", &k);
      while (k--) {
        scanf("%d", &r);
        v[i].push_back(r);
      }
      sort(v[i].begin(), v[i].end());
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int pre = i - 1;
      pre = pre == 0 ? n : pre;
      int next = i + 1;
      next = next == n + 1 ? 1 : next;
      for (int j = 1; j < v[i].size(); j++) {
        int x = upper_bound(v[pre].begin(), v[pre].end(), v[i][j]) -
                upper_bound(v[pre].begin(), v[pre].end(), v[i][j - 1]);
        int y = upper_bound(v[next].begin(), v[next].end(), v[i][j]) -
                upper_bound(v[next].begin(), v[next].end(), v[i][j - 1]);
        if (x != y) ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
