#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v[1009];
int main() {
  cin >> n;
  for (int i = 1, c, t; i <= n; i++) {
    v[i].push_back(0);
    cin >> c;
    while (c--) cin >> t, v[i].push_back(t);
  }
  for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int p = i - 1, pp = i + 1;
    if (p == 0) p = n;
    if (pp == n + 1) pp = 1;
    for (int j = 2; j < v[i].size(); j++) {
      int a = v[i][j - 1], b = v[i][j];
      int t = upper_bound(v[p].begin(), v[p].end(), b) -
              upper_bound(v[p].begin(), v[p].end(), a);
      int tt = upper_bound(v[pp].begin(), v[pp].end(), b) -
               upper_bound(v[pp].begin(), v[pp].end(), a);
      ans += (t != tt);
    }
  }
  cout << ans << endl;
}
