#include <bits/stdc++.h>
using namespace std;
const int maxN = 100100;
const int inf = 1e17;
int n, m;
struct tt {
  int gt, cs;
} a[maxN];
int cnt[maxN], tr[maxN], ph[maxN], pre[maxN];
void nhap() {
  cin >> n;
  m = 0;
  for (int i = 0; i < n; i++) {
    int k, x;
    scanf("%i", &k);
    for (int j = 0; j < k; j++) {
      scanf("%i", &a[m].gt);
      a[m++].cs = i + 1;
    }
  }
}
bool cmp(tt x, tt y) { return x.gt < y.gt; }
void trai(int i) {
  if (i == 0) i = n;
  ++tr[i];
}
void phai(int i) {
  if (i == n + 1) i = 1;
  ++ph[i];
}
void init() {
  int dem = 0;
  sort(a, a + m, cmp);
  memset(pre, 255, sizeof(pre));
  memset(cnt, 0, sizeof(cnt));
  memset(tr, 0, sizeof(ph));
  memset(ph, 0, sizeof(tr));
  for (int i = 0; i < m; i++) {
    trai(a[i].cs - 1);
    phai(a[i].cs + 1);
    if (tr[a[i].cs] != ph[a[i].cs] && pre[a[i].cs] >= 0) ++dem;
    tr[a[i].cs] = ph[a[i].cs] = 0;
    pre[a[i].cs] = a[i].gt;
  }
  cout << dem;
}
void xuly() {}
int main() {
  nhap();
  init();
  xuly();
  return 0;
}
