#include <bits/stdc++.h>
using namespace std;
int n, s;
int d[111];
int v[111][111], t[111][111], st[111][111];
int main() {
  scanf("%d%d", &n, &s);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", d + i);
    for (int j = 1; j <= d[i]; ++j) {
      scanf("%d%d", &v[i][j], &t[i][j]);
      st[i][j] = st[i][j - 1] + t[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j) {
      for (int l = 1, r = 1, k = 0, x = 0, y = 0, now = 0;
           l <= d[i] && r <= d[j];) {
        if (st[i][l] < st[j][r]) {
          x += (st[i][l] - now) * v[i][l], y += (st[i][l] - now) * v[j][r];
          now = st[i][l];
          l++;
        } else if (st[i][l] > st[j][r]) {
          x += (st[j][r] - now) * v[i][l], y += (st[j][r] - now) * v[j][r];
          now = st[j][r];
          r++;
        } else {
          x += (st[j][r] - now) * v[i][l], y += (st[j][r] - now) * v[j][r];
          now = st[j][r];
          r++;
          l++;
        }
        if (x > y) ans += (k == j), k = i;
        if (x < y) ans += (k == i), k = j;
      }
    }
  printf("%d\n", ans);
  return 0;
}
