#include <bits/stdc++.h>
size_t push(const std::vector<size_t>& v, size_t id, size_t val) {
  while (id < v.size() && v[id] < val) {
    id += 1;
  }
  return id;
}
size_t solve(const std::vector<size_t>& m, const std::vector<size_t>& l,
             const std::vector<size_t>& r) {
  size_t l_ptr = push(l, 0, m[0]);
  size_t r_ptr = push(r, 0, m[0]);
  size_t result = 0;
  for (size_t m_ptr = 1; m_ptr < m.size(); ++m_ptr) {
    const size_t l_next = push(l, l_ptr, m[m_ptr]);
    const size_t r_next = push(r, r_ptr, m[m_ptr]);
    if (l_next - l_ptr != r_next - r_ptr) {
      result += 1;
    }
    l_ptr = l_next;
    r_ptr = r_next;
  }
  return result;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  size_t n;
  std::cin >> n;
  std::vector<std::vector<size_t>> ps(n);
  for (size_t i = 0; i < n; ++i) {
    size_t k;
    std::cin >> k;
    ps[i].resize(k);
    for (size_t j = 0; j < k; ++j) {
      std::cin >> ps[i][j];
    }
    sort(ps[i].begin(), ps[i].end());
  }
  size_t result = 0;
  for (size_t i = 0; i < n; ++i) {
    result += solve(ps[i], ps[(i + 1) % n], ps[(i + n - 1) % n]);
  }
  std::cout << result << '\n';
}
