#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1024;
int n;
vector<int> V[MAXN];
int main() {
  cin >> n;
  for (register int i = (0); i < (int)(n); ++i) {
    int x;
    cin >> x;
    V[i].resize(x);
    for (register int j = (0); j < (int)(x); ++j) cin >> V[i][j];
    sort((V[i]).begin(), (V[i]).end());
  }
  int cnt = 0;
  for (register int cur = (0); cur < (int)(n); ++cur) {
    vector<int> a = V[(cur + n - 1) % n], b = V[(cur + 1) % n], c = V[cur];
    for (register int i = (1); i < (int)(((int)(c).size())); ++i) {
      int x = upper_bound((a).begin(), (a).end(), c[i]) -
              lower_bound((a).begin(), (a).end(), c[i - 1]);
      int y = upper_bound((b).begin(), (b).end(), c[i]) -
              lower_bound((b).begin(), (b).end(), c[i - 1]);
      if (x != y) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
