#include <bits/stdc++.h>
using namespace std;
int main() {
  int t[101][101];
  int v[101][101];
  int k[101];
  int n, s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> v[i][j] >> t[i][j];
      if (j > 0) {
        t[i][j] += t[i][j - 1];
      }
    }
  }
  int count(0);
  for (int p = 0; p < n; p++) {
    for (int q = p + 1; q < n; q++) {
      int distp(0);
      int distq(0);
      int lastp(0);
      int lastq(0);
      int now(0);
      int dt(0);
      int indp(0);
      int indq(0);
      while (distp < s && distq < s) {
        if (t[p][indp] <= t[q][indq]) {
          dt = t[p][indp] - now;
        } else {
          dt = t[q][indq] - now;
        }
        lastp = distp;
        distp += v[p][indp] * dt;
        lastq = distq;
        distq += v[q][indq] * dt;
        if (lastp != 0 && lastp < lastq && distp >= distq) {
          if (!(distp == distq && distp == s)) count++;
        }
        if (lastq != 0 && lastp > lastq && distp <= distq) {
          if (!(distp == distq && distp == s)) count++;
        }
        if (t[p][indp] < t[q][indq]) {
          now = t[p][indp];
          indp++;
        } else if (t[p][indp] > t[q][indq]) {
          now = t[q][indq];
          indq++;
        } else {
          assert(t[p][indp] == t[q][indq]);
          now = t[q][indq];
          indp++;
          indq++;
        }
      }
    }
  }
  cout << count;
}
