#include <bits/stdc++.h>
using namespace std;
const int maxn = 210;
int ans, dist[maxn][2], t[maxn][maxn], v[maxn][maxn], k[maxn], n, d;
void solve(int p1, int p2) {
  int l = 0, nowp1 = 1, nowp2 = 1, nowt = 0, nowd1 = 0, nowd2 = 0;
  while (nowp1 <= k[p1] && nowp2 <= k[p2]) {
    if (t[p1][nowp1] < t[p2][nowp2]) {
      nowd1 += (t[p1][nowp1] - nowt) * v[p1][nowp1];
      nowd2 += (t[p1][nowp1] - nowt) * v[p2][nowp2];
      nowt = t[p1][nowp1];
      nowp1++;
    } else {
      nowd1 += (t[p2][nowp2] - nowt) * v[p1][nowp1];
      nowd2 += (t[p2][nowp2] - nowt) * v[p2][nowp2];
      nowt = t[p2][nowp2];
      nowp2++;
    }
    int p = l;
    while (p && dist[p][0] == dist[p][1]) p--;
    if (p) {
      if (dist[p][0] < dist[p][1] && nowd1 > nowd2) ans++;
      if (dist[p][1] < dist[p][0] && nowd2 > nowd1) ans++;
    }
    l++;
    dist[l][0] = nowd1;
    dist[l][1] = nowd2;
  }
}
int main() {
  scanf("%d%d", &n, &d);
  for (int a = 1; a <= n; a++) {
    scanf("%d", &k[a]);
    for (int b = 1; b <= k[a]; b++) {
      scanf("%d%d", &v[a][b], &t[a][b]);
      t[a][b] += t[a][b - 1];
    }
  }
  for (int a = 1; a <= n; a++)
    for (int b = a + 1; b <= n; b++) solve(a, b);
  printf("%d\n", ans);
  return 0;
}
