#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const int maxk = 105;
int dv[maxn][maxk], dt[maxn][maxk];
int st[maxn][maxk];
int cnt[maxn];
int n, s, ret;
void init() {
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; i++) {
    scanf("%d", &cnt[i]);
    for (int j = 0; j < cnt[i]; j++) {
      scanf("%d%d", &dv[i][j], &dt[i][j]);
      st[i][j] = dt[i][j] + (j ? st[i][j - 1] : 0);
    }
  }
}
int Fmin(int x, int y) { return x < y ? x : y; }
void work() {
  ret = 0;
  for (int u = 0; u < n; u++)
    for (int v = u + 1; v < n; v++) {
      int uc = 0, vc = 0, us = 0, vs = 0, cur = 0, first = -1;
      while (uc < cnt[u] && vc < cnt[v]) {
        int nxt = Fmin(st[u][uc], st[v][vc]);
        us += (nxt - cur) * dv[u][uc];
        vs += (nxt - cur) * dv[v][vc];
        if (nxt == st[u][uc]) uc++;
        if (nxt == st[v][vc]) vc++;
        cur = nxt;
        if (us < vs)
          ret += first == v, first = u;
        else if (us > vs)
          ret += first == u, first = v;
      }
    }
}
void print() { printf("%d\n", ret); }
int main() {
  init();
  work();
  print();
  return 0;
}
