#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > leedescripcion() {
  int n;
  cin >> n;
  vector<pair<int, int> > v(n);
  for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  return v;
}
struct elem {
  int tiempo, coche, velocidad;
};
bool operator<(elem e1, elem e2) { return e1.tiempo < e2.tiempo; }
void anyade(vector<pair<int, int> > &u, vector<elem> &v, int coche) {
  int t = 0;
  for (int i = 0; i < int(u.size()); i++) {
    pair<int, int> p = u[i];
    elem e;
    e.tiempo = t;
    t += p.second;
    e.coche = coche;
    e.velocidad = p.first;
    v.push_back(e);
  }
  {
    elem e;
    e.tiempo = t;
    e.velocidad = 0;
    e.coche = coche;
    v.push_back(e);
  }
}
int cruces(vector<pair<int, int> > &u0, vector<pair<int, int> > &u1) {
  int count = 0;
  vector<elem> v;
  anyade(u0, v, 0);
  anyade(u1, v, 1);
  sort(v.begin(), v.end());
  int pos0 = 0;
  int pos1 = 0;
  int v0 = 0;
  int v1 = 0;
  int lider = -1;
  int t = 0;
  for (int i = 0; i < int(v.size()); i++) {
    elem e = v[i];
    int nextt = e.tiempo;
    int duracion = nextt - t;
    pos0 += v0 * duracion;
    pos1 += v1 * duracion;
    if (e.coche == 0)
      v0 = e.velocidad;
    else
      v1 = e.velocidad;
    int nextlider = lider;
    if (pos0 > pos1)
      nextlider = 0;
    else if (pos1 > pos0)
      nextlider = 1;
    if (nextlider != lider and lider != -1) count++;
    lider = nextlider;
    t = nextt;
  }
  return count;
}
int main() {
  int n, distancia;
  cin >> n >> distancia;
  vector<vector<pair<int, int> > > v(n);
  for (int i = 0; i < n; i++) v[i] = leedescripcion();
  int count = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) count += cruces(v[i], v[j]);
  cout << count << endl;
}
