#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int> > ve;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    vector<int> v;
    for (int i = 0; i < m; i++) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    sort(v.begin(), v.end());
    ve.push_back(v);
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    int x = i + 1;
    int y = i - 1;
    if (y == -1) y = n - 1;
    if (x == n) x = 0;
    for (int j = 0; j < ve[i].size() - 1; j++) {
      int l = ve[i][j];
      int r = ve[i][j + 1];
      int c1 = lower_bound(ve[x].begin(), ve[x].end(), l) - ve[x].begin();
      int c2 = lower_bound(ve[x].begin(), ve[x].end(), r) - ve[x].begin() - 1;
      int c3 = lower_bound(ve[y].begin(), ve[y].end(), l) - ve[y].begin();
      int c4 = lower_bound(ve[y].begin(), ve[y].end(), r) - ve[y].begin() - 1;
      int len1 = c2 - c1 + 1;
      int len2 = c4 - c3 + 1;
      if (len2 != len1) res++;
    }
  }
  cout << res << endl;
  return 0;
}
