#include <bits/stdc++.h>
using namespace std;
int n, S, sz[105], v[105][105], t[105][105];
int tp1[105], tp2[105];
int main() {
  scanf("%d%d", &n, &S);
  for (int i = 0; i < n; i++) {
    scanf("%d", &sz[i]);
    for (int j = 1; j <= sz[i]; j++) {
      scanf("%d%d", &v[i][j], &t[i][j]);
    }
  }
  int ret = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      int s1 = 0, p1 = 1;
      int s2 = 0, p2 = 1;
      memcpy(tp1, t[i], sizeof(tp1));
      memcpy(tp2, t[j], sizeof(tp2));
      while (p1 <= sz[i] && p2 <= sz[j]) {
        int tt = min(tp1[p1], tp2[p2]);
        tp1[p1] -= tt;
        tp2[p2] -= tt;
        int ns1 = tt * v[i][p1] + s1;
        int ns2 = tt * v[j][p2] + s2;
        if (tp1[p1] == 0) p1++;
        if (tp2[p2] == 0) p2++;
        if (s1 < s2 &&
            (ns1 > ns2 || ns1 == ns2 && ns1 != S && v[i][p1] > v[j][p2]))
          ret++;
        if (s1 > s2 &&
            (ns1 < ns2 || ns1 == ns2 && ns1 != S && v[i][p1] < v[j][p2]))
          ret++;
        s1 = ns1;
        s2 = ns2;
      }
    }
  printf("%d\n", ret);
  return 0;
}
