#include <bits/stdc++.h>
using namespace std;
int cal(int i, int l, int r, vector<vector<int> >& v) {
  int ans = 0;
  int n = v[i].size();
  vector<int> left(n, 0), right(n, 0);
  for (int j = 0; j < n; j++) {
    int indl =
        lower_bound((v[l]).begin(), (v[l]).end(), v[i][j]) - v[l].begin();
    int indr =
        lower_bound((v[r]).begin(), (v[r]).end(), v[i][j]) - v[r].begin();
    left[j] = max(0, indl);
    right[j] = max(0, indr);
    if (j != 0 && (left[j] - left[j - 1] != right[j] - right[j - 1])) {
      ans++;
    }
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  vector<vector<int> > v(n);
  for (int i = 0; i < int(n); i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      v[i].push_back(a);
    }
    sort((v[i]).begin(), (v[i]).end());
  }
  int ans = 0;
  ans += (cal(0, n - 1, 1, v));
  ans += (cal(n - 1, n - 2, 0, v));
  for (int i = 1; i < n - 1; i++) {
    ans += (cal(i, i - 1, i + 1, v));
  }
  cout << ans << endl;
  ;
}
