#include <bits/stdc++.h>
using namespace std;
struct Sector {
  int ls, rs, ld, ud;
  Sector(int lowDist, int upDist) : ls(0), rs(0), ld(lowDist), ud(upDist) {}
};
vector<vector<Sector> > sectors;
vector<vector<int> > bridges;
int n, k, ans;
int ind(int i) {
  if (i < 0)
    return n + i;
  else
    return i % n;
}
void read() {
  ans = 0;
  scanf("%d", &n);
  bridges.resize(n);
  sectors.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &k);
    bridges[i].resize(k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &bridges[i][j]);
    }
    sort(bridges[i].begin(), bridges[i].end());
    vector<int>::iterator iter = bridges[i].begin();
    for (iter; iter + 1 != bridges[i].end(); iter++) {
      sectors[i].push_back(Sector(*iter, *(iter + 1)));
    }
  }
}
void addJointLeft(vector<Sector>::iterator sect) {
  sect->ls++;
  int dif = sect->ls - sect->rs;
  if (dif == 0)
    ans--;
  else if (dif == 1)
    ans++;
}
void addJointRight(vector<Sector>::iterator sect) {
  sect->rs++;
  int dif = sect->rs - sect->ls;
  if (dif == 0)
    ans--;
  else if (dif == 1)
    ans++;
}
void solve() {
  for (int i = 0; i < n; i++) {
    vector<Sector>::iterator cur = sectors[ind(i)].begin();
    vector<Sector>::iterator curEnd = sectors[ind(i)].end();
    vector<int>::iterator prev = bridges[ind(i - 1)].begin();
    vector<int>::iterator prevEnd = bridges[ind(i - 1)].end();
    vector<int>::iterator next = bridges[ind(i + 1)].begin();
    vector<int>::iterator nextEnd = bridges[ind(i + 1)].end();
    bool inc = true;
    while (cur != curEnd) {
      inc = true;
      if (prev != prevEnd) {
        if (*prev > cur->ld && *prev < cur->ud) cur->ls++;
        if (*prev < cur->ud) {
          prev++;
          inc = false;
        }
      }
      if (next != nextEnd) {
        if (*next > cur->ld && *next < cur->ud) cur->rs++;
        if (*next < cur->ud) {
          next++;
          inc = false;
        }
      }
      if (inc) {
        if (cur->ls != cur->rs) ans++;
        cur++;
      }
    }
  }
}
void print() { printf("%d\n", ans); }
int main() {
  read();
  solve();
  print();
}
