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