#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll hell = 998244353;
int main() {
  ll n;
  cin >> n;
  vector<ll> v[n];
  for (ll i = 0; i < n; ++i) {
    ll x;
    cin >> x;
    for (ll j = 0; j < x; ++j) {
      ll y;
      cin >> y;
      v[i].push_back(y);
    }
    v[i].push_back(100009);
    sort(v[i].begin(), v[i].end());
  }
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    ll e = (i != 0) ? i - 1 : n - 1;
    ll f = (i != n - 1) ? i + 1 : 0;
    for (ll j = 1; j < v[i].size() - 1; ++j) {
      ll v1 = v[i][j];
      ll v2 = v[i][j - 1];
      ll c1 = lower_bound(v[e].begin(), v[e].end(), v1) -
              lower_bound(v[e].begin(), v[e].end(), v2);
      ll c2 = lower_bound(v[f].begin(), v[f].end(), v1) -
              lower_bound(v[f].begin(), v[f].end(), v2);
      if (c1 != c2) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
