#include <bits/stdc++.h>
using namespace std;
int n, s, p1, p2, now, nxt, n1, n2, ans;
int x[110], v[110][110], t[110][110];
bool flag;
int main() {
  int i, j, p, q;
  scanf("%d%d", &n, &s);
  for (i = 1; i <= n; i++) {
    scanf("%d", x + i);
    for (j = 1; j <= x[i]; j++) {
      scanf("%d%d", &v[i][j], &t[i][j]);
      t[i][j] += t[i][j - 1];
    }
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j < i; j++) {
      p = q = 1;
      p1 = p2 = now = flag = 0;
      while (p1 < s && p2 < s) {
        nxt = min(t[i][p], t[j][q]);
        n1 = p1 + v[i][p] * (nxt - now);
        n2 = p2 + v[j][q] * (nxt - now);
        if (p1 && p1 <= p2 && n1 > n2 && !flag)
          ans++;
        else if (p2 && p2 <= p1 && n2 > n1 && flag)
          ans++;
        p1 = n1, p2 = n2, now = nxt;
        if (p1 > p2) flag = 1;
        if (p2 > p1) flag = 0;
        while (p < x[i] && t[i][p] <= now) p++;
        while (q < x[j] && t[j][q] <= now) q++;
      }
    }
  printf("%d\n", ans);
  return 0;
}
