#include <bits/stdc++.h>
using namespace std;
int n, k[110], v[110][110], t[110][110], res, s, i, j;
int ktra(long long &s1, long long &s2, long long f1, long long f2, int &p) {
  int res = ((s1 - s2) * (f1 - f2) < 0) || ((s1 == s2) && (p * (f1 - f2) < 0));
  if (f1 > f2) p = 1;
  if (f1 < f2) p = -1;
  s1 = f1;
  s2 = f2;
  return res;
}
int tinh(int i, int j) {
  long long s1 = 0, s2 = 0;
  int i1 = 0, i2 = 0, t1 = t[i][0], t2 = t[j][0], d = 0, tt, p = 0;
  while (s1 < s && s2 < s) {
    tt = min(t1, t2);
    d += ktra(s1, s2, s1 + tt * v[i][i1], s2 + tt * v[j][i2], p);
    t1 -= tt;
    t2 -= tt;
    if (t1 == 0 && i1 < k[i] - 1) t1 = t[i][++i1];
    if (t2 == 0 && i2 < k[j] - 1) t2 = t[j][++i2];
  }
  return d;
}
int main() {
  cin >> n >> s;
  for (i = 0; i < n; i++) {
    cin >> k[i];
    for (j = 0; j < k[i]; j++) cin >> v[i][j] >> t[i][j];
  }
  res = 0;
  for (i = 0; i < n - 1; i++)
    for (j = i + 1; j < n; j++) res += tinh(i, j);
  cout << res;
}
