#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll md = 1000000007;
ll exp(ll a, ll b) {
  ll r = 1ll;
  while (b > 0) {
    if (b & 1) {
      r = r * (a % md);
      r = (r + md) % md;
    }
    b >>= 1;
    a = (a % md) * (a % md);
    a = (a + md) % md;
  }
  return (r + md) % md;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
T Min(T a, T b) {
  if (a < b) return a;
  return b;
}
template <class T>
T Max(T a, T b) {
  if (a > b) return a;
  return b;
}
string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vector<bool> v) {
  string res;
  for (bool x : v) res += char('0' + x);
  return res;
}
template <size_t S>
string to_string(bitset<S> b) {
  string res;
  for (auto x : b) res += char('0' + x);
  return res;
}
template <class T>
string to_string(T v) {
  bool f = 1;
  string res;
  for (auto& x : v) {
    if (!f) res += ' ';
    f = 0;
    res += to_string(x);
  }
  return res;
}
void DBG() { cerr << "]" << '\n'; }
template <class H, class... T>
void DBG(H h, T... t) {
  cerr << to_string(h);
  if (sizeof...(t)) cerr << ", ";
  DBG(t...);
}
long long ffind(vector<ll>& v, long long l, long long r) {
  return upper_bound((v).begin(), (v).end(), r) -
         upper_bound((v).begin(), (v).end(), l);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m;
  cin >> n;
  vector<vector<ll> > sector(n), bridge(n);
  for (ll i = 0; i <= n - 1; ++i) {
    cin >> m;
    sector[i].resize(m);
    for (ll j = 0; j <= m - 1; ++j) cin >> sector[i][j];
  }
  for (ll i = 0; i <= n - 1; ++i) {
    long long j = (i - 1 + n) % n;
    for (auto& x : sector[i]) bridge[i].push_back(x), bridge[j].push_back(x);
  }
  for (ll i = 0; i <= n - 1; ++i)
    sort((bridge[i]).begin(), (bridge[i]).end()),
        sort((sector[i]).begin(), (sector[i]).end());
  long long ans = 0;
  for (ll i = 0; i <= n - 1; ++i) {
    long long j = (i - 1 + n) % n;
    for (ll k = 0; k <= (long long)(sector[i]).size() - 2; ++k) {
      long long l = sector[i][k], r = sector[i][k + 1];
      if (ffind(bridge[i], l, r) != ffind(bridge[j], l, r)) ++ans;
    }
  }
  cout << ans;
  cout << '\n';
  return 0;
}
