#include <bits/stdc++.h>
using namespace std;
vector<int> dists[1 << 10];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int sz;
    scanf("%d", &sz);
    dists[i].resize(sz);
    for (int j = 0; j < sz; j++) {
      scanf("%d", &dists[i][j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int prev = (i + n - 1) % n;
    int next = (i + 1) % n;
    vector<pair<int, int> > events;
    for (int j = 0; j < dists[i].size(); j++) {
      events.push_back(make_pair(dists[i][j], 0));
    }
    for (int j = 0; j < dists[prev].size(); j++) {
      events.push_back(make_pair(dists[prev][j], -1));
    }
    for (int j = 0; j < dists[next].size(); j++) {
      events.push_back(make_pair(dists[next][j], 1));
    }
    sort(events.begin(), events.end());
    int diff = 1 << 30;
    ans--;
    for (int i = 0; i < events.size(); i++) {
      if (events[i].second == 0) {
        if (diff != 0) {
          ans++;
        }
        diff = 0;
      } else {
        diff += events[i].second;
      }
    }
  }
  printf("%d\n", ans);
}
