#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int n;
vector<int> a[1011];
int get(int t, int l, int r) {
  if (l > a[t][a[t].size() - 1]) return 0;
  if (r < a[t][0]) return 0;
  int i = lower_bound(a[t].begin(), a[t].end(), l) - a[t].begin();
  int j = upper_bound(a[t].begin(), a[t].end(), r) - a[t].begin() - 1;
  if (i > j) return 0;
  return j - i + 1;
}
int main() {
  while (scanf("%d", &n) == 1) {
    for (int i = (1), _b = (n); i <= _b; i++) {
      a[i].clear();
      int k;
      scanf("%d", &k);
      a[i].resize(k);
      for (int x = 0, _a = (k); x < _a; x++) scanf("%d", &a[i][x]);
      sort(a[i].begin(), a[i].end());
    }
    int res = 0;
    for (int i = (1), _b = (n); i <= _b; i++) {
      for (int x = 0, _a = (a[i].size() - 1); x < _a; x++) {
        int l = a[i][x] + 1, r = a[i][x + 1] - 1;
        if (l > r) continue;
        int ii = i + 1;
        if (ii > n) ii = 1;
        int u = get(ii, l, r);
        ii = i - 1;
        if (ii < 1) ii = n;
        int v = get(ii, l, r);
        if (u != v) ++res;
      }
    }
    printf("%d\n", res);
  }
  return 0;
}
