#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
vector<int> adj[N];
int n;
int check(int L, int R, int i) {
  int dx = lower_bound(adj[i].begin(), adj[i].end(), L) - adj[i].begin();
  int dx2 = lower_bound(adj[i].begin(), adj[i].end(), R) - adj[i].begin() - 1;
  if (dx >= adj[i].size()) return 0;
  if (adj[i][dx] > R) return 0;
  return dx2 - dx + 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int p;
      scanf("%d", &p);
      adj[i].push_back(p);
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(adj[i].begin(), adj[i].end());
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < adj[i].size(); j++) {
      int start = adj[i][j - 1];
      int _end = adj[i][j];
      int after = i == n ? 1 : i + 1;
      int before = i == 1 ? n : i - 1;
      int onLeft = check(start, _end, before);
      int onRight = check(start, _end, after);
      ans += onLeft != onRight;
    }
  }
  printf("%d\n", ans);
  return 0;
}
