#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vec[101];
int n, m;
int func(vector<pair<int, int> > A, vector<pair<int, int> > B) {
  int a = 0, b = 0, ret = 0;
  int ia = 0, ib = 0;
  while (ia < A.size() && ib < B.size()) {
    int Time = min(A[ia].second, B[ib].second);
    A[ia].second -= Time;
    B[ib].second -= Time;
    int aa = a + A[ia].first * Time;
    int bb = b + B[ib].first * Time;
    if (A[ia].second == 0) ia++;
    if (B[ib].second == 0) ib++;
    if (a > b &&
        (aa < bb || (aa == bb && bb != m && A[ia].first < B[ib].first)))
      ret++;
    if (a < b &&
        (aa > bb || (aa == bb && bb != m && A[ia].first > B[ib].first)))
      ret++;
    a = aa, b = bb;
  }
  return ret;
}
int main() {
  cin >> n >> m;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    while (k--) {
      int a, b;
      cin >> a >> b;
      vec[i].push_back(make_pair(a, b));
    }
    for (int j = 0; j < i; j++) {
      ans += func(vec[i], vec[j]);
    }
  }
  cout << ans << endl;
  return 0;
}
