#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int inf = 2e9 + 10;
const long long INF = 2e18 + 10;
const int MOD = 1e9 + 7;
int n;
vector<int> a[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    for (int j = 1; j <= x; ++j) {
      int u;
      cin >> u;
      a[i].push_back(u);
    }
  }
  for (int i = 0; i < n; ++i) sort((a[i]).begin(), (a[i]).end());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int f1 = ((i + n - 1) % n), f2 = (i + 1) % n;
    for (int j = 0; j < (int)(a[i]).size() - 1; ++j) {
      int cnt1 = (lower_bound((a[f1]).begin(), (a[f1]).end(), a[i][j + 1]) -
                  lower_bound((a[f1]).begin(), (a[f1]).end(), a[i][j]));
      int cnt2 = (lower_bound((a[f2]).begin(), (a[f2]).end(), a[i][j + 1]) -
                  lower_bound((a[f2]).begin(), (a[f2]).end(), a[i][j]));
      if (cnt1 != cnt2) ans++;
    }
  }
  cout << ans;
  return 0;
}
