#include <bits/stdc++.h>
using namespace std;
int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
class debug_t {
 public:
  template <typename T>
  debug_t& operator<<(const T& o) {
    return *this;
  }
  void end() {
    *this << "\nExecution Time = " << clock() * 1.0 / CLOCKS_PER_SEC << '\n';
    exit(0);
  }
} dout;
vector<vector<int>> ve;
int get_pos(int x, int y, int i) {
  int up = lower_bound(ve[i].begin(), ve[i].end(), x) - ve[i].begin();
  int bottom = lower_bound(ve[i].begin(), ve[i].end(), y) - ve[i].begin() - 1;
  return bottom - up;
}
int main() {
  int n;
  cin >> n;
  ve.assign(n + 5, vector<int>());
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      ve[i].push_back(x);
    }
    sort(ve[i].begin(), ve[i].end());
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    int right_pos = (i + 1) % n;
    int left_pos = (i - 1 + n) % n;
    for (int j = 0; j < ve[i].size() - 1; j++) {
      int left = get_pos(ve[i][j], ve[i][j + 1], right_pos);
      int right = get_pos(ve[i][j], ve[i][j + 1], left_pos);
      if (left - right) res++;
    }
  }
  cout << res << "\n";
  dout.end();
}
