#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  scanf("%d %d", &n, &s);
  int k[n], v[n][100], t[n][100], sumt[n][101];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &k[i]);
    sumt[i][0] = 0;
    for (int j = 0; j < k[i]; ++j) {
      scanf("%d %d", &v[i][j], &t[i][j]);
      sumt[i][j + 1] = sumt[i][j] + t[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int lead = (v[i][0] > v[j][0] ? i : j);
      for (int a = 0, b = 0, t = 0, x1 = 0, x2 = 0; a < k[i] && b < k[j];) {
        int t2 = min(sumt[i][a + 1], sumt[j][b + 1]);
        x1 += (t2 - t) * v[i][a];
        x2 += (t2 - t) * v[j][b];
        if (lead == i) {
          if (x2 > x1) {
            ++ans;
            lead = j;
          }
        } else {
          if (x1 > x2) {
            ++ans;
            lead = i;
          }
        }
        if (sumt[i][a + 1] == t2) ++a;
        if (sumt[j][b + 1] == t2) ++b;
        t = t2;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
