#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vpii = vector<pair<int, int> >;
using vpll = vector<pair<long long, long long> >;
using vld = vector<long double>;
using vb = vector<bool>;
const int inf = (int)1e9 + 7;
const long long llinf = (long long)1e18 + 7;
void solve() {
  long long n;
  cin >> n;
  vll a[n];
  for (long long i = 0; i < n; i++) {
    long long ki;
    cin >> ki;
    for (long long j = 0; j < ki; j++) {
      long long x;
      cin >> x;
      a[i].push_back(x);
    }
    sort(a[i].begin(), a[i].end());
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long l, r;
    l = (i - 1 + n) % n;
    r = (i + 1 + n) % n;
    for (long long j = 1; j <= (a[i].size()) - 1; j++) {
      ans += (upper_bound(a[r].begin(), a[r].end(), a[i][j]) -
                  upper_bound(a[r].begin(), a[r].end(), a[i][j - 1]) !=
              upper_bound(a[l].begin(), a[l].end(), a[i][j]) -
                  upper_bound(a[l].begin(), a[l].end(), a[i][j - 1]));
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int ttt = 1;
  while (ttt--) {
    solve();
  }
}
