#include <bits/stdc++.h>
struct node {
  int v, t;
  int x, y;
};
const int maxn = 100;
const int maxk = 100;
node a[maxn][maxk];
int k[maxk];
int n, s;
int ans = 0;
void solve(int l1, int l2);
int main() {
  using std::cin;
  using std::cout;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> a[i][j].v >> a[i][j].t;
      if (j == 0) {
        a[i][j].x = a[i][j].t;
        a[i][j].y = a[i][j].v * a[i][j].t;
      } else {
        a[i][j].x = a[i][j - 1].x + a[i][j].t;
        a[i][j].y = a[i][j - 1].y + a[i][j].v * a[i][j].t;
      }
    }
  }
  int l1, l2;
  ans = 0;
  for (l1 = 0; l1 < n; l1++)
    for (l2 = l1 + 1; l2 < n; l2++) solve(l1, l2);
  cout << ans << '\n';
  return 0;
}
void solve(int l1, int l2) {
  int t0, t, y1, y2;
  long long d1, d2, d3;
  int j1, j2;
  t = 0;
  j1 = 0;
  j2 = 0;
  bool get_d1, get_d2;
  get_d1 = false;
  get_d2 = false;
  y1 = 0;
  y2 = 0;
  while (j1 < k[l1] && j2 < k[l2]) {
    t0 = t;
    if (a[l1][j1].x < a[l2][j2].x) {
      t = a[l1][j1].x;
      y1 = a[l1][j1].y;
      y2 += a[l2][j2].v * (t - t0);
      j1++;
    } else if (a[l1][j1].x > a[l2][j2].x) {
      t = a[l2][j2].x;
      y2 = a[l2][j2].y;
      y1 += a[l1][j1].v * (t - t0);
      j2++;
    } else {
      t = a[l1][j1].x;
      y1 = a[l1][j1].y;
      y2 = a[l2][j2].y;
      j1++;
      j2++;
    }
    if (!get_d1) {
      d1 = y2 - y1;
      get_d1 = true;
    } else if (!get_d2) {
      d2 = y2 - y1;
      if (d1 * d2 < 0) ans++;
      get_d2 = true;
    } else {
      d3 = y2 - y1;
      if (d2 == 0) {
        if (d1 * d3 < 0) ans++;
      } else {
        if (d2 * d3 < 0) ans++;
      }
      d1 = d2;
      d2 = d3;
    }
  }
}
