#include <bits/stdc++.h>
using namespace std;
int n, s, ans;
map<int, int> x[111];
void work(map<int, int> &x, map<int, int> &y) {
  set<int> f;
  for (auto t : x) f.insert(t.first);
  for (auto t : y) f.insert(t.first);
  int lt(0), sx(0), sy(0), vx, vy;
  bool c(x.begin()->second > y.begin()->second);
  f.erase(0);
  for (auto t : f) {
    vx = x.lower_bound(t)->second, vy = y.lower_bound(t)->second;
    sx += vx * (t - lt), sy += vy * (t - lt);
    if ((sx < sy && c) || (sx > sy && !c)) ++ans, c = !c;
    lt = t;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> s;
  for (int i = 1, k; i <= n; ++i) {
    cin >> k;
    for (int j = 1, v, t, st(0); j <= k; ++j) cin >> v >> t, x[i][st += t] = v;
    x[i][100000000] = 0;
  }
  for (int i = 1; i < n; ++i)
    for (int j = i + 1; j <= n; ++j) work(x[i], x[j]);
  cout << ans << endl;
  return 0;
}
