#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
vector<int> vec[N];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int k;
    scanf("%d", &k);
    vec[i].resize(k);
    for (int j = 0; j < k; ++j) scanf("%d", &vec[i][j]);
    sort(vec[i].begin(), vec[i].end());
  }
  int out = 0;
  for (int i = 0; i < n; ++i) {
    int L = (i - 1 + n) % n, R = (i + 1) % n;
    int jL = 0, jR = 0;
    while (jL < vec[L].size() && vec[L][jL] < vec[i][0]) jL++;
    while (jR < vec[R].size() && vec[R][jR] < vec[i][0]) jR++;
    for (int j = 1; j < vec[i].size(); j++) {
      int cL = 0, cR = 0;
      while (jL < vec[L].size() && vec[L][jL] < vec[i][j]) jL++, cL++;
      while (jR < vec[R].size() && vec[R][jR] < vec[i][j]) jR++, cR++;
      if (cL != cR) out++;
    }
  }
  cout << out << endl;
}
