#include <bits/stdc++.h>
typedef struct Lnode {
  int t;
  int v;
  struct Lnode *next;
} node;
node *record[101];
int flag[100001];
int height(int t, int n) {
  int result = 0, i;
  node *p;
  p = record[n];
  while (t - p->t > 0) {
    result += p->t * p->v;
    t -= p->t;
    p = p->next;
  }
  result += p->v * t;
  return result;
}
int mark(int n) {
  int temp = 0;
  node *p;
  p = record[n];
  while (p->next != NULL) {
    temp += p->t;
    flag[temp] = 1;
    p = p->next;
  }
  flag[temp + p->t] = 1;
  return temp + p->t;
}
int main() {
  int start, i, flag1, t, n, s, j, cross = 0, temp, k, h1, h2, h3, h4, l;
  node *p;
  scanf("%d%d", &n, &s);
  for (i = 1; i <= n; i++) {
    scanf("%d", &k);
    p = (node *)malloc(sizeof(node));
    scanf("%d%d", &p->v, &p->t);
    record[i] = p;
    while (--k) {
      p->next = (node *)malloc(sizeof(node));
      p = p->next;
      scanf("%d%d", &p->v, &p->t);
    }
    p->next = NULL;
  }
  for (i = 1; i <= n - 1; i++) {
    for (j = i + 1; j <= n; j++) {
      memset(flag, 0, sizeof flag);
      t = mark(i);
      if (mark(j) < t) t = mark(j);
      k = 1;
      while (flag[k] == 0) k++;
      start = l = k;
      while (l < t) {
        l++;
        if (flag[l] == 1) {
          flag[k] = l;
          k = l;
        }
      }
      flag[t] = -1;
      l = start;
      k = 0;
      h1 = height(k, i);
      h2 = height(k, j);
      flag1 = 0;
      while (1) {
        h3 = height(l, i);
        h4 = height(l, j);
        if ((h1 < h2 && h3 > h4) || (h1 > h2 && h3 < h4))
          cross++;
        else if (h3 == h4 && flag[l] != -1 && h2 - h1 != 0)
          flag1 = h2 - h1;
        else if (h1 == h2) {
          if ((flag1 < 0 && h4 - h3 > 0) || (flag1 > 0 && h4 - h3 < 0)) cross++;
        }
        h1 = h3;
        h2 = h4;
        k = flag[k];
        l = flag[l];
        if (l == -1) break;
      }
    }
  }
  printf("%d\n", cross);
  return 0;
}
