#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:267386880")
using namespace std;
vector<int> d[1005];
int count(int wh, int to) {
  int ans(lower_bound((d[wh]).begin(), (d[wh]).end(), to) - d[wh].begin());
  if (binary_search((d[wh]).begin(), (d[wh]).end(), to)) ++ans;
  return ans;
}
int count(int wh, int from, int to) {
  int ans(count(wh, to) - count(wh, from));
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i(0); i <= ((int)(n)-1); ++i) {
    int k;
    scanf("%d", &k);
    d[i].reserve(k);
    for (int j(0); j <= ((int)(k)-1); ++j) {
      int a;
      scanf("%d", &a);
      d[i].push_back(a);
    }
    sort((d[i]).begin(), (d[i]).end());
  }
  int ans(0);
  for (int i(0); i <= ((int)(n)-1); ++i) {
    int nxt((i + 1) % n);
    int prv((i - 1 + n) % n);
    for (int j(0); j <= ((int)(((int)d[i].size()) - 1) - 1); ++j) {
      if (count(nxt, d[i][j], d[i][j + 1]) != count(prv, d[i][j], d[i][j + 1]))
        ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}
