#include <bits/stdc++.h>
using namespace std;
int v[111][111];
int t[111][111];
int k[111];
int calc(int x, int y) {
  int lead = v[x][1] < v[y][1];
  int cnt = 0;
  int p = 1, q = 1;
  int time = 0;
  int posx = 0, posy = 0;
  while (p <= k[x] && q <= k[y]) {
    if (t[x][p] < t[y][q]) {
      posx += (t[x][p] - time) * v[x][p];
      posy += (t[x][p] - time) * v[y][q];
      time = t[x][p++];
      if (lead == 0) {
        if (posy > posx) {
          ++cnt;
          lead = 1;
        }
      } else {
        if (posx > posy) {
          ++cnt;
          lead = 0;
        }
      }
    } else {
      posx += (t[y][q] - time) * v[x][p];
      posy += (t[y][q] - time) * v[y][q];
      time = t[y][q++];
      if (lead == 0) {
        if (posy > posx) {
          ++cnt;
          lead = 1;
        }
      } else {
        if (posx > posy) {
          ++cnt;
          lead = 0;
        }
      }
    }
  }
  return cnt;
}
int main() {
  int n, s;
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &k[i]);
    for (int j = 1; j <= k[i]; ++j) {
      scanf("%d%d", &v[i][j], &t[i][j]);
      t[i][j] = t[i][j - 1] + t[i][j];
    }
    t[i][k[i] + 1] = 1000000000;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) ans += calc(i, j);
  }
  printf("%d\n", ans);
  return 0;
}
