#include <bits/stdc++.h>
using namespace std;
int n, s, k;
long long ans;
vector<pair<int, int> > T[101];
int main() {
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; i++) {
    int tot = 0;
    for (scanf("%d", &k); k--;) {
      int speed, time;
      scanf("%d%d", &speed, &time);
      tot += time;
      T[i].push_back(make_pair(speed, tot));
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      int di = 0, dj = 0;
      int t = 0, pi = 0, pj = 0, ddi = 0, ddj = 0;
      while (pi < (int)T[i].size() && pj < (int)T[j].size()) {
        int dt = min(T[i][pi].second, T[j][pj].second) - t;
        bool which = T[i][pi].second < T[j][pj].second;
        ddi += T[i][pi].first * dt, ddj += T[j][pj].first * dt;
        int ndi = di + ddi, ndj = dj + ddj;
        if ((di - dj) * (long long)(ndi - ndj) < 0) ans++;
        if (which)
          pi++;
        else
          pj++;
        t += dt;
        if (ndi != ndj) di = ndi, dj = ndj, ddi = ddj = 0;
      }
    }
  printf("%I64d\n", ans);
}
