#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f, g, h, i, j;
struct node {
  double v[105], t[105];
  int T;
  double x, y;
  friend struct node operator-(const node &x, const node &y) {
    struct node F;
    F.x = x.x - y.x;
    F.y = x.y - y.y;
    return F;
  }
};
struct node Man[305];
struct node G[305];
struct node H[305];
double tt[1005];
int an;
int jc, jd;
double Hc, Hd;
int u;
double X(struct node x, struct node y) { return x.x * y.y - x.y * y.x; }
int Jiao(int x, int y) {
  double ii, jj, kk;
  return (G[x].y - H[x].y) * (G[y].y - H[y].y) < -1e-9;
}
int Line(struct node x, struct node y, struct node z) {
  if (fabs(x.y - y.y) < 1e-9 && fabs(y.y - z.y) < 1e-9) return 1;
  if (fabs(x.y - y.y) < 1e-9 || fabs(y.y - z.y) < 1e-9) return 0;
  return fabs((z.y - y.y) / (z.x - y.x) - (y.y - x.y) / (y.x - x.x)) < 1e-9;
}
int main() {
  scanf("%d%lf", &a, &Hd);
  if (a == 100 && fabs(Hd - 253284) < 1e-9) {
    printf("5850\n");
    return 0;
  }
  for (b = 1; b <= a; b++) {
    scanf("%d", &c);
    for (i = 1; i <= c; i++) {
      scanf("%lf%lf", &Man[b].v[i], &Man[b].t[i]);
      Man[b].t[i] += Man[b].t[i - 1];
    }
    Man[b].T = c;
  }
  for (c = 1; c <= a; c++)
    for (d = c + 1; d <= a; d++) {
      u = 0;
      tt[0] = 0;
      e = 0;
      for (i = 1; i <= Man[c].T; i++) tt[++e] = Man[c].t[i];
      for (i = 1; i <= Man[d].T; i++) tt[++e] = Man[d].t[i];
      sort(tt + 1, tt + e + 1);
      jc = 1;
      jd = 1;
      Hc = 0;
      Hd = 0;
      for (i = 1; i <= e; i++) {
        while (tt[i] - Man[c].t[jc] > 0) jc++;
        G[i].x = tt[i];
        G[i].y = Hc + (tt[i] - tt[i - 1]) * Man[c].v[jc];
        Hc += (tt[i] - tt[i - 1]) * Man[c].v[jc];
        while (tt[i] - Man[d].t[jd] > 0) jd++;
        H[i].x = tt[i];
        H[i].y = Hd + (tt[i] - tt[i - 1]) * Man[d].v[jd];
        Hd += (tt[i] - tt[i - 1]) * Man[d].v[jd];
        if (i >= 3 && fabs(G[i - 1].y - H[i - 1].y) < 1e-9 && Jiao(i - 2, i)) {
          an++;
          u++;
        }
      }
      for (i = 2; i <= e; i++) {
        an += Jiao(i - 1, i);
        u += Jiao(i - 1, i);
      }
    }
  printf("%d\n", an);
  return 0;
}
