#include <bits/stdc++.h>
using namespace std;
int n, k, x;
vector<vector<int> > data;
vector<int> sz;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  data.resize(n);
  sz.resize(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> k;
    sz[i] = k;
    for (int j = 0; j < (int)(k); j++) {
      cin >> x;
      data[i].push_back(x);
    }
    sort(data[i].begin(), data[i].end());
  }
  long long res = 0LL;
  for (int i = 0; i < (int)(n); i++) {
    int sprev = (i - 1 + n) % n;
    int snext = (i + 1 + n) % n;
    int pidx = 0, nidx = 0;
    for (int j = 0; j < (int)(sz[i]); j++) {
      int tpidx = pidx;
      int tnidx = nidx;
      while (tpidx < sz[sprev] && data[sprev][tpidx] < data[i][j]) tpidx++;
      while (tnidx < sz[snext] && data[snext][tnidx] < data[i][j]) tnidx++;
      if (j > 0 && tpidx - pidx != tnidx - nidx) {
        res++;
      }
      pidx = tpidx;
      nidx = tnidx;
    }
  }
  cout << res << "\n";
  return 0;
}
