#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int n;
vector<vector<int> > p;
vector<int> k;
void solve() {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int l = (i + n - 1) % n, r = (i + 1) % n;
    int li = 0, ri = 0;
    for (int j = 0; j + 1 < k[i]; j++) {
      int acnt = 0, bcnt = 0, x = p[i][j], y = p[i][j + 1];
      for (; li < k[l] && p[l][li] < y; li++) {
        if (p[l][li] > x) acnt++;
      }
      for (; ri < k[r] && p[r][ri] < y; ri++) {
        if (p[r][ri] > x) bcnt++;
      }
      if (acnt != bcnt) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  cin >> n;
  p = vector<vector<int> >(n);
  k = vector<int>(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &k[i]);
    p[i] = vector<int>(k[i]);
    for (int j = 0; j < k[i]; j++) {
      scanf("%d", &p[i][j]);
    }
    sort(p[i].begin(), p[i].end());
  }
  solve();
}
