#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const long long int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
void cp() {
  int n;
  cin >> n;
  vector<vector<int>> arr(n), left(n), right(n);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    arr[i] = left[i] = right[i] = vector<int>(k);
    for (int &x : arr[i]) cin >> x;
    sort(arr[i].begin(), arr[i].end());
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int nx = (i - 1 + n) % n;
    for (int j = 0; j < ((int)arr[i].size()); j++) {
      int lo = 0, hi = ((int)arr[nx].size()) - 1;
      int me = 0;
      while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (arr[nx][mid] < arr[i][j])
          me = mid + 1, lo = mid + 1;
        else
          hi = mid - 1;
      }
      left[i][j] = me;
    }
    nx = (i + 1) % n;
    for (int j = 0; j < ((int)arr[i].size()); j++) {
      int lo = 0, hi = ((int)arr[nx].size()) - 1;
      int me = 0;
      while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (arr[nx][mid] < arr[i][j])
          me = mid + 1, lo = mid + 1;
        else
          hi = mid - 1;
      }
      right[i][j] = me;
    }
    for (int j = 1; j < ((int)arr[i].size()); j++) {
      int l = left[i][j] - (j ? left[i][j - 1] : 0);
      int r = right[i][j] - (j ? right[i][j - 1] : 0);
      if (l != r) ans++;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    cp();
  }
  return 0;
}
