#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> p[1007];
int f(const vector<int> &s, int x) {
  int lo = 0, hi = int(s.size()) - 1;
  while (lo < hi) {
    int mid = lo + (hi - lo) / 2;
    if (s[mid] > x)
      hi = mid;
    else
      lo = mid + 1;
  }
  if (s.back() <= x) return -1;
  return lo;
}
int g(const vector<int> &s, int x) {
  int lo = 0, hi = int(s.size()) - 1;
  while (lo < hi) {
    int mid = lo + (hi - lo + 1) / 2;
    if (s[mid] < x)
      lo = mid;
    else
      hi = mid - 1;
  }
  if (s.front() >= x) return -1;
  return lo;
}
int main() {
  n;
  cin >> n;
  for (int(i) = (int)(0); (i) < (int)(n); ++(i)) {
    int k;
    cin >> k;
    p[i].resize(k);
    for (int(j) = (int)(0); (j) < (int)(k); ++(j)) cin >> p[i][j];
    sort(p[i].begin(), p[i].end());
  }
  int ans = 0;
  for (int(i) = (int)(0); (i) < (int)(n); ++(i)) {
    int m = int(p[i].size());
    int pre = (n + i - 1) % n, nex = (i + 1) % n;
    for (int(j) = (int)(1); (j) < (int)(m); ++(j)) {
      int lo = p[i][j - 1], hi = p[i][j];
      int a, b, cnt1, cnt2;
      a = f(p[pre], lo), b = g(p[pre], hi);
      cnt1 = b >= a ? b - a + 1 : 0;
      if (a == -1 || b == -1) cnt1 = 0;
      a = f(p[nex], lo), b = g(p[nex], hi);
      cnt2 = b >= a ? b - a + 1 : 0;
      if (a == -1 || b == -1) cnt2 = 0;
      if (cnt1 != cnt2) ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
