#include <bits/stdc++.h>
using namespace std;
int c[1005];
vector<int> p[1005];
int main() {
  int n, num = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    for (int j = 1; j <= c[i]; j++) {
      int x;
      cin >> x;
      p[i].push_back(x);
    }
    sort(p[i].begin(), p[i].end());
  }
  for (int i = 1; i <= n; i++) {
    int pre = i - 1, sx = i + 1;
    if (pre == 0) pre = n;
    if (sx == n + 1) sx = 1;
    for (int j = 1; j < p[i].size(); j++) {
      int l1 = lower_bound(p[pre].begin(), p[pre].end(), p[i][j - 1]) -
               p[pre].begin();
      int r1 = upper_bound(p[pre].begin(), p[pre].end(), p[i][j]) -
               p[pre].begin() - 1;
      int l2 =
          lower_bound(p[sx].begin(), p[sx].end(), p[i][j - 1]) - p[sx].begin();
      int r2 =
          upper_bound(p[sx].begin(), p[sx].end(), p[i][j]) - p[sx].begin() - 1;
      if (r1 - l1 + 1 != r2 - l2 + 1) num++;
    }
  }
  cout << num << endl;
}
