#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
T gcd(T a, T b) {
  return b != T(0) ? gcd(b, a % b) : a;
}
const int N = 1 << 10;
vector<int> p[N], bridge[N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (auto i = (0); i < (n); ++i) {
    int k;
    cin >> k;
    for (auto j = (0); j < (k); ++j) {
      int q;
      cin >> q;
      p[i].emplace_back(q);
      p[(i + 1) % n].emplace_back(q);
      bridge[i].emplace_back(q);
    }
  }
  for (auto i = (0); i < (n); ++i) {
    sort(begin(p[i]), end(p[i]));
    sort(begin(bridge[i]), end(bridge[i]));
  }
  int ans = 0;
  for (auto i = (0); i < (n); ++i) {
    for (auto j = (0); j < (int((bridge[i]).size()) - 1); ++j) {
      int left = lower_bound(begin(p[i]), end(p[i]), bridge[i][j + 1]) -
                 lower_bound(begin(p[i]), end(p[i]), bridge[i][j]);
      int right =
          lower_bound(begin(p[(i + 1) % n]), end(p[(i + 1) % n]),
                      bridge[i][j + 1]) -
          lower_bound(begin(p[(i + 1) % n]), end(p[(i + 1) % n]), bridge[i][j]);
      if (left != right) ++ans;
    }
  }
  cout << ans;
}
