#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > web;
int main() {
  int n;
  cin >> n;
  web.push_back(vector<int>());
  for (int i = 1; i <= n; i++) {
    web.push_back(vector<int>());
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int x;
      cin >> x;
      web[i].push_back(x);
    }
    sort(web[i].begin(), web[i].end());
  }
  web.push_back(vector<int>());
  web[0] = web[n];
  web[n + 1] = web[1];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int len = web[i].size();
    for (int j = 1; j < len; j++) {
      int l = upper_bound(web[i - 1].begin(), web[i - 1].end(), web[i][j]) -
              web[i - 1].begin();
      l = l -
          (upper_bound(web[i - 1].begin(), web[i - 1].end(), web[i][j - 1]) -
           web[i - 1].begin());
      int r = upper_bound(web[i + 1].begin(), web[i + 1].end(), web[i][j]) -
              web[i + 1].begin();
      r = r -
          (upper_bound(web[i + 1].begin(), web[i + 1].end(), web[i][j - 1]) -
           web[i + 1].begin());
      if (l != r) ans++;
    }
  }
  cout << ans << endl;
}
