#include <bits/stdc++.h>
using namespace std;
struct event {
  int t, n, x, v;
  event(int t_, int n_, int x_, int v_) : t(t_), n(n_), x(x_), v(v_) {}
  bool operator<(const event& e) const {
    if (t != e.t) return t < e.t;
    if (n != e.n) return n < e.n;
    return x < e.x;
  }
};
int pos[100], oldpos[100];
int V[100];
int main() {
  int n, k, t, v, dt, s, x;
  vector<event> events;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> k;
    t = 0;
    x = 0;
    for (int j = 0; j < k; j++) {
      cin >> v >> dt;
      events.push_back(event(t, i, x, v));
      t += dt;
      x += v * dt;
    }
    events.push_back(event(t, i, x, 0));
  }
  long long cnt = 0;
  sort(events.begin(), events.end());
  int time = 0;
  for (int i = 0; i < events.size(); i++) {
    int curtime = events[i].t;
    for (int j = 0; j < n; j++) {
      pos[j] += (curtime - time) * V[j];
    }
    for (int ii = 0; ii < n; ii++)
      for (int jj = 0; jj < n; jj++) {
        if (oldpos[jj] != 0 || oldpos[ii] != 0)
          if (pos[jj] > pos[ii] && oldpos[jj] <= oldpos[ii]) cnt++;
      }
    memcpy(oldpos, pos, sizeof(int) * 100);
    V[events[i].n] = events[i].v;
    time = curtime;
  }
  cout << cnt << endl;
  return 0;
}
