#include <bits/stdc++.h>
using namespace std;
struct po {
  int tim, v, id;
};
int v[101];
int tmp[101];
int s[101];
vector<po> vv;
bool cmp(po x, po y) { return x.tim < y.tim; }
int mp[101][101];
int main() {
  int i, j, k, n, nn, x, y, ss;
  while (~scanf("%d%d", &n, &ss)) {
    vv.clear();
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) mp[i][j] = 0;
    for (i = 1; i <= n; i++) {
      v[i] = s[i] = 0;
      scanf("%d", &nn);
      int ti = 0;
      po tt;
      for (j = 0; j < nn; j++) {
        scanf("%d%d", &x, &y);
        tt.tim = ti;
        tt.v = x;
        tt.id = i;
        vv.push_back(tt);
        ti += y;
      }
      tt.tim = ti;
      tt.v = 0;
      tt.id = i;
      vv.push_back(tt);
    }
    sort(vv.begin(), vv.end(), cmp);
    int now = 0;
    int ans = 0;
    for (k = 0; k < vv.size(); k++) {
      int tim = vv[k].tim;
      int id = vv[k].id;
      int vvv = vv[k].v;
      if (tim == now) {
        v[id] = vvv;
        continue;
      }
      for (i = 1; i <= n; i++) {
        tmp[i] = s[i] + v[i] * (tim - now);
      }
      for (i = 1; i <= n; i++) {
        if (s[i] == ss) continue;
        for (j = i + 1; j <= n; j++) {
          if (s[j] == ss) continue;
          if (tmp[i] > tmp[j]) {
            if (mp[i][j] == -1) ans++;
            mp[i][j] = 1;
          } else if (tmp[i] < tmp[j]) {
            if (mp[i][j] == 1) ans++;
            mp[i][j] = -1;
          }
        }
      }
      for (i = 1; i <= n; i++) {
        s[i] = tmp[i];
      }
      now = tim;
      v[id] = vvv;
    }
    printf("%d\n", ans);
  }
  return 0;
}
