#include <bits/stdc++.h>
const int N = 110;
int k[N], v[N][N], t[N][N], tt[N][N];
int main() {
  int n, s, i, j, l, px, py, temp, tx, ty, sx, sy, ans = 0;
  scanf("%d%d", &n, &s);
  for (i = 1; i <= n; i++) {
    scanf("%d", &k[i]);
    for (j = 1; j <= k[i]; j++) scanf("%d%d", &v[i][j], &t[i][j]);
  }
  for (i = 2; i <= n; i++)
    for (j = 1; j < i; j++) {
      sx = 0;
      sy = 0;
      tx = 0;
      ty = 0;
      for (l = 1; l <= k[i]; l++) tt[i][l] = t[i][l];
      for (l = 1; l <= k[j]; l++) tt[j][l] = t[j][l];
      px = 1;
      py = 1;
      while (px <= k[i] && py <= k[j]) {
        if (tt[i][px] < tt[j][py])
          temp = tt[i][px];
        else
          temp = tt[j][py];
        sx += v[i][px] * temp;
        sy += v[j][py] * temp;
        if (tx != ty) {
          if (sx != sy) {
            if ((tx < ty && sx > sy) || (tx > ty && sx < sy)) ans++;
            tx = sx;
            ty = sy;
          }
        } else {
          tx = sx;
          ty = sy;
        }
        tt[i][px] -= temp;
        if (tt[i][px] == 0) px++;
        tt[j][py] -= temp;
        if (tt[j][py] == 0) py++;
      }
    }
  printf("%d", ans);
}
