#include <bits/stdc++.h>
using namespace std;
vector<int> v[1100];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int x;
      cin >> x;
      v[i].push_back(x);
      if (i == 1) v[n + 1].push_back(x);
      if (i == n) v[0].push_back(x);
    }
  }
  for (int i = 0; i <= n + 1; i++) {
    sort(v[i].begin(), v[i].end());
    v[i].push_back(1000000000);
  }
  int c = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i].size() < 3) continue;
    int m = v[i].size();
    int l = 0;
    int r = 0;
    int cur = 0;
    while (v[i - 1][l] < v[i][cur]) l++;
    while (v[i + 1][r] < v[i][cur]) r++;
    while (cur != m - 2) {
      int a = l;
      int b = r;
      cur++;
      while (v[i - 1][l] < v[i][cur]) l++;
      while (v[i + 1][r] < v[i][cur]) r++;
      if ((l - a) != (r - b)) c++;
    }
  }
  cout << c << endl;
  return 0;
}
