#include <bits/stdc++.h>
using namespace std;
vector<int> bridge[100010];
vector<int> points[100010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int m;
    scanf("%d", &m);
    for (int j = 0; j < m; ++j) {
      int t;
      scanf("%d", &t);
      bridge[i].push_back(t);
      int li = i + 1, ri = i;
      if (li >= n) li = 0;
      points[li].push_back(t);
      points[ri].push_back(t);
    }
    sort(bridge[i].begin(), bridge[i].end());
  }
  for (int i = 0; i < n; ++i) sort(points[i].begin(), points[i].end());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int li = i + 1, ri = i;
    if (li >= n) li = 0;
    int l[100010] = {}, r[100010] = {};
    for (int j = 0, index = 0, cur; j < points[ri].size(); ++j) {
      if (index == bridge[i].size() - 1) break;
      if (points[ri][j] == bridge[i][0])
        cur = j;
      else if (points[ri][j] == bridge[i][index + 1])
        r[index] = j - cur, index++, cur = j;
    }
    for (int j = 0, index = 0, cur; j < points[li].size(); ++j) {
      if (index == bridge[i].size() - 1) break;
      if (points[li][j] == bridge[i][0])
        cur = j;
      else if (points[li][j] == bridge[i][index + 1])
        l[index] = j - cur, index++, cur = j;
    }
    for (int j = 0; j < bridge[i].size() - 1; ++j) ans += l[j] == r[j] ? 0 : 1;
  }
  printf("%d\n", ans);
  return 0;
}
