#include <bits/stdc++.h>
using namespace std;
const int N = 120;
struct seg {
  int v, t;
} a[N][N];
int k[N], t[2 * N];
int main() {
  const int W1 = 1, W2 = 2, WX = 3;
  int len, n, m, i, j, z, h, x, y, num = 0, dt, was, now, i0, j0;
  cin >> n >> len;
  for (i = 0; i < n; ++i) {
    cin >> k[i];
    for (j = 0; j < k[i]; ++j) {
      cin >> a[i][j].v;
      cin >> a[i][j].t;
      if (j > 0) a[i][j].t += a[i][j - 1].t;
    }
  }
  for (i = 0; i < n; ++i) {
    for (j = 0; j < i; ++j) {
      for (h = 0; h < k[i]; ++h) t[h] = a[i][h].t;
      for (h = 0; h < k[j]; ++h) t[h + k[i]] = a[j][h].t;
      h = k[i] + k[j];
      t[h++] = 0;
      sort(t, t + h);
      x = y = 0;
      was = WX;
      i0 = j0 = 0;
      for (z = 1; z < h; ++z) {
        dt = t[z] - t[z - 1];
        while (a[i][i0].t < t[z] && i0 < k[i]) ++i0;
        while (a[j][j0].t < t[z] && j0 < k[j]) ++j0;
        x += dt * a[i][i0].v;
        y += dt * a[j][j0].v;
        if (x > y)
          now = W1;
        else if (x < y)
          now = W2;
        else
          now = WX;
        if (was == W1 && now == W2 || was == W2 && now == W1) {
          was = now;
          ++num;
        }
        if (was == WX) was = now;
      }
    }
  }
  cout << num << endl;
  return 0;
}
