#include <bits/stdc++.h>
using namespace std;
const double eps(1e-8);
typedef struct vv {
  int a, b;
  bool operator<(const vv &q) const { return a < q.a; }
} vv;
vector<vv> s;
vector<int> v[110000];
int n;
void pus(int a, int b) {
  vv t;
  t.a = a;
  t.b = b;
  s.push_back(t);
}
int solve(int a, int mid, int b) {
  s.clear();
  for (int i = 0; i < (v[a].size()); ++i) pus(v[a][i], 0);
  for (int i = 0; i < (v[mid].size()); ++i) pus(v[mid][i], 1);
  for (int i = 0; i < (v[b].size()); ++i) pus(v[b][i], 2);
  sort(s.begin(), s.end());
  int ret = 0, flag = false, x = 0, y = 0;
  for (int i = 0; i < (s.size()); ++i) {
    if (s[i].b == 1) {
      if (flag && x != y) ret++;
      flag = true;
      x = y = 0;
    } else if (s[i].b == 0)
      x++;
    else
      y++;
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < (k); ++j) {
      int a;
      scanf("%d", &a);
      v[i].push_back(a);
      if (i <= 2) v[i + n].push_back(a);
    }
  }
  int ans = 0;
  for (int i = (1); i <= (n); ++i) ans += solve(i, i + 1, i + 2);
  cout << ans << endl;
}
