#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
int n, s;
int k[1 << 7];
pair<int, int> a[100][100];
int o[1 << 7];
int v[1 << 7];
int p[1 << 7];
int m;
pair<int, int> ev[1 << 14];
int near[100][100];
int tn[100][100];
int nx[1 << 7];
inline void init() {
  m = 0;
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &k[i]);
    int curt = 0;
    for (int j = 0; j < k[i]; ++j) {
      scanf("%d%d", &a[i][j].first, &a[i][j].second);
      ev[m++] = pair<int, int>(curt, i);
      curt += a[i][j].second;
    }
    ev[m++] = pair<int, int>(curt, i);
  }
  sort(ev, ev + m);
  memset(near, 0, sizeof near);
}
inline int isOver(int &x) { return (o[x] == k[x]); }
int main() {
  init();
  memset(o, -1, sizeof o);
  memset(v, 0, sizeof v);
  memset(p, 0, sizeof p);
  memset(tn, 0, sizeof tn);
  int res = 0;
  int FLAG = 0;
  for (int t = 0; t < m;) {
    ++FLAG;
    int curt = ev[t].first;
    while (t < m && ev[t].first == curt) {
      int x = ev[t].second;
      ++o[x];
      if (!isOver(x)) v[x] = a[x][o[x]].first;
      ++t;
    }
    if (t == m) break;
    int nextt = ev[t].first;
    int dif = nextt - curt;
    for (int i = 0; i < n; ++i) {
      if (isOver(i)) continue;
      nx[i] = p[i] + dif * v[i];
    }
    for (int x = 0; x < n; ++x) {
      if (isOver(x)) continue;
      for (int y = x + 1; y < n; ++y) {
        if (isOver(y)) continue;
        int i = x;
        int j = y;
        if (v[i] < v[j]) swap(i, j);
        if (p[i] > p[j]) continue;
        if (p[i] == p[j]) {
          if (near[i][j] != FLAG) continue;
          ++res;
          continue;
        }
        if (nx[i] == nx[j]) {
          tn[i][j] = FLAG + 1;
          continue;
        }
        if (nx[i] > nx[j]) ++res;
      }
    }
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j) near[i][j] = tn[i][j];
    for (int i = 0; i < n; ++i) {
      if (isOver(i)) continue;
      p[i] = nx[i];
    }
  }
  printf("%d\n", res);
  return 0;
}
