#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  int t;
  bool flag = false;
  while ((t = getchar()) != '-' && (t < '0' || t > '9'))
    ;
  if (t == '-') flag = true, t = getchar();
  x = t - '0';
  while ((t = getchar()) >= '0' && t <= '9') x = x * 10 + t - '0';
  if (flag) x = -x;
}
const int maxn = 1010;
int n, cnt[maxn];
vector<int> v[maxn];
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(cnt[i]);
    for (int j = 1, tmp; j <= cnt[i]; ++j) read(tmp), v[i].push_back(tmp);
    sort(v[i].begin(), v[i].end());
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x = i == 1 ? n : i - 1, y = i == n ? 1 : i + 1, c1 = 0, c2 = 0, p1, p2;
    for (int j = 0; j < cnt[i]; ++j) {
      p1 = c1, p2 = c2;
      while (c1 < cnt[x] && v[x][c1] <= v[i][j]) ++c1;
      while (c2 < cnt[y] && v[y][c2] <= v[i][j]) ++c2;
      if (j && c1 - p1 != c2 - p2) ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
