#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
vector<int> p[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    p[i].resize(k);
    for (int j = 0; j < k; j++) cin >> p[i][j];
    sort(p[i].begin(), p[i].end());
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int pre = i ? i - 1 : n - 1;
    int nxt = (i + 1) % n;
    int p1 = 0, p2 = 0;
    for (int j = 0; j < (int)p[i].size(); j++) {
      int cnt = 0;
      while (p1 < (int)p[pre].size() && p[pre][p1] < p[i][j]) cnt++, p1++;
      while (p2 < (int)p[nxt].size() && p[nxt][p2] < p[i][j]) cnt--, p2++;
      if (cnt != 0 && j != 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
