#include <bits/stdc++.h>
using namespace std;
int n, m, k, nxt, tt, x, y, ans;
vector<int> side[1111], sector[1111];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &m);
    nxt = i + 1;
    if (nxt == n) nxt = 0;
    for (int j = 0; j < m; ++j) {
      scanf("%d", &k);
      side[i].push_back(k);
      side[nxt].push_back(k);
      sector[i].push_back(k);
    }
  }
  for (int i = 0; i < n; ++i) {
    sort(side[i].begin(), side[i].end());
    sort(sector[i].begin(), sector[i].end());
  }
  ans = 0;
  for (int i = 0; i < n; ++i) {
    tt = (int)sector[i].size();
    nxt = i + 1;
    if (nxt == n) nxt = 0;
    for (int j = 1; j < tt; ++j) {
      x = lower_bound(side[i].begin(), side[i].end(), sector[i][j]) -
          upper_bound(side[i].begin(), side[i].end(), sector[i][j - 1]);
      y = lower_bound(side[nxt].begin(), side[nxt].end(), sector[i][j]) -
          upper_bound(side[nxt].begin(), side[nxt].end(), sector[i][j - 1]);
      ans += (x != y);
    }
  }
  printf("%d", ans);
  return 0;
}
