#include <bits/stdc++.h>
using namespace std;
const int N = 201, S = 1000000;
int M[N], V[N][N], T[N][N + 1];
int X[2 * N], Y[2 * N], Z[2 * N];
int n, m, s;
int ans;
int stat(int x, int y) {
  int SA = 0, SB = 0;
  for (int i = 0; i < M[x]; i++) SA += T[x][i];
  for (int j = 0; j < M[y]; j++) SB += T[y][j];
  if (SA < SB)
    T[x][M[x]] = SB - SA;
  else
    T[y][M[y]] = SA - SB;
  X[0] = Y[0] = 0, m = 1;
  int i = 0, j = 0;
  if (T[x][0] > T[y][0]) swap(x, y);
  int dt = T[y][0];
  while (i < M[x] || j < M[y]) {
    while (i <= M[x] && dt >= 0) {
      X[m] = X[m - 1] + V[x][i] * T[x][i], Y[m] = Y[m - 1] + V[y][j] * T[x][i];
      dt -= T[x][i], m++, i++;
    }
    if (dt <= 0) {
      X[m - 1] += V[x][--i] * dt, Y[m - 1] += V[y][j++] * dt;
      dt = -dt;
    }
    while (j <= M[y] && dt >= 0) {
      X[m] = X[m - 1] + V[x][i] * T[y][j], Y[m] = Y[m - 1] + V[y][j] * T[y][j];
      dt -= T[y][j], m++, j++;
    }
    if (dt <= 0) {
      X[m - 1] += V[x][i++] * dt, Y[m - 1] += V[y][--j] * dt;
      dt = -dt;
    }
  }
  T[x][M[x]] = T[y][M[y]] = 0;
  int res = 0;
  for (int i = 1; i < m; i++) {
    if (X[i] < Y[i] && X[i - 1] > Y[i - 1] ||
        Y[i] < X[i] && Y[i - 1] > X[i - 1])
      res++;
    else if (i < m - 1 && X[i] == Y[i] &&
             (X[i - 1] < Y[i - 1] && X[i + 1] > Y[i + 1] ||
              Y[i - 1] < X[i - 1] && Y[i + 1] < X[i + 1]))
      res++;
  }
  return res;
}
int cnt(int x, int y) {
  int s1 = 0, s2 = 0, t1 = 0, t2 = 0, i = 0, j = 0, m = 0;
  while (i < M[x] && j < M[y]) {
    if (t1 + T[x][i] < t2 + T[y][j]) {
      s1 += V[x][i] * T[x][i], t1 += T[x][i];
      X[m] = s1, Y[m] = s2 + (t1 - t2) * V[y][j];
      m++, i++;
    } else if (t1 + T[x][i] > t2 + T[y][j]) {
      s2 += V[y][j] * T[y][j], t2 += T[y][j];
      X[m] = s1 + (t2 - t1) * V[x][i], Y[m] = s2;
      m++, j++;
    } else {
      s1 += V[x][i] * T[x][i], t1 += T[x][i];
      s2 += V[y][j] * T[y][j], t2 += T[y][j];
      X[m] = s1, Y[m] = s2;
      m++, i++, j++;
    }
  }
  int res = 0;
  for (int i = 1; i < m; i++) {
    if (X[i] < Y[i] && X[i - 1] > Y[i - 1] ||
        Y[i] < X[i] && Y[i - 1] > X[i - 1])
      res++;
    else if (i < m - 1 && X[i] == Y[i] &&
             (X[i - 1] < Y[i - 1] && X[i + 1] > Y[i + 1] ||
              Y[i - 1] < X[i - 1] && Y[i + 1] > X[i + 1]))
      res++;
  }
  return res;
}
int main() {
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> M[i];
    for (int j = 0; j < M[i]; j++) cin >> V[i][j] >> T[i][j];
  }
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) ans += cnt(i, j);
  cout << ans << endl;
}
