#include <bits/stdc++.h>
using namespace std;
int n, s, ans;
struct node {
  int v, t;
};
node p[105][105];
int ti[105][105], dis[105][105];
int q[105];
int h[201];
int op[201];
double work(int k, int dist) {
  for (int i = 1; i <= q[k]; i++) {
    if (dis[k][i] >= dist) {
      return ti[k][i - 1] + (dist - dis[k][i - 1]) * 1.0 / p[k][i].v;
    }
  }
}
int main() {
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &q[i]);
    for (int j = 1; j <= q[i]; j++) {
      scanf("%d %d", &p[i][j].v, &p[i][j].t);
      ti[i][j] = ti[i][j - 1] + p[i][j].t;
      dis[i][j] = dis[i][j - 1] + p[i][j].t * p[i][j].v;
    }
    ti[i][q[i] + 1] = 99999999;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int t1 = 1, t2 = 1, x1 = 0, x2 = 0;
      int temp = 0;
      int temp2 = 3;
      while (t1 <= q[i] || t2 <= q[j]) {
        int temp1 = min(ti[i][t1], ti[j][t2]);
        x1 += (temp1 - temp) * p[i][t1].v;
        x2 += (temp1 - temp) * p[j][t2].v;
        if (ti[i][t1] < ti[j][t2])
          t1++;
        else
          t2++;
        if (x1 > x2 && temp2 == 0) ans++;
        if (x1 < x2 && temp2 == 1) ans++;
        if (x1 < x2) temp2 = 0;
        if (x1 > x2) temp2 = 1;
        temp = temp1;
      }
    }
  }
  cout << ans;
  return 0;
}
