#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int Getchar() {
  int tmp = 0;
  char ch;
  while (ch = getchar())
    if (ch >= '0' && ch <= '9') break;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) tmp = tmp * 10 + ch - '0';
  return tmp;
}
int k[maxn];
int d[maxn][maxn], t[maxn][maxn];
int v[maxn][maxn];
int n, s;
void init() {
  n = Getchar(), s = Getchar();
  for (int i = 1; i <= n; i++) {
    k[i] = Getchar();
    for (int j = 1; j <= k[i]; j++) {
      v[i][j] = Getchar(), t[i][j] = Getchar();
      d[i][j] = d[i][j - 1] + v[i][j] * t[i][j];
      t[i][j] += t[i][j - 1];
    }
  }
}
void work() {
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < i; j++)
      for (int a = 0, b = 0, x = 0; a < k[i] && b < k[j];) {
        if (t[i][a + 1] < t[j][b + 1])
          ++a;
        else
          ++b;
        int l = max(t[i][a], t[j][b]);
        int sa = d[i][a] + (l - t[i][a]) * v[i][a + 1];
        int sb = d[j][b] + (l - t[j][b]) * v[j][b + 1];
        if (sa < sb) {
          if (x == 1) ++ans;
          x = -1;
        }
        if (sa > sb) {
          if (x == -1) ++ans;
          x = 1;
        }
      }
  printf("%d\n", ans);
}
int main() {
  init();
  work();
  return 0;
}
