#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n >> s;
  vector<vector<int> > t(n);
  vector<vector<int> > v(n);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    t[i].resize(k);
    v[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> v[i][j] >> t[i][j];
    }
    for (int j = 1; j < k; j++) {
      t[i][j] += t[i][j - 1];
    }
  }
  long long ans = 0;
  vector<int> e;
  for (int p = 0; p < n; p++) {
    for (int q = p + 1; q < n; q++) {
      e.clear();
      merge((t[p]).begin(), (t[p]).end(), (t[q]).begin(), (t[q]).end(),
            back_inserter(e));
      e.resize(unique((e).begin(), (e).end()) - e.begin());
      int x1, x2, ne1, ne2, i, j;
      x1 = x2 = i = j = ne1 = ne2 = 0;
      int lt = 0;
      for (auto tt : e) {
        int dt = (tt - lt);
        if (ne1 != ne2) {
          x1 = ne1;
          x2 = ne2;
        }
        ne1 += dt * v[p][i];
        ne2 += dt * v[q][j];
        if (((x1 < x2) && (ne1 > ne2)) || ((x1 > x2) && (ne1 < ne2))) {
          ans++;
        }
        if (t[p][i] == tt) {
          i++;
        }
        if (t[q][j] == tt) {
          j++;
        }
        if (i == t[p].size() || j == t[q].size()) {
          break;
        }
        lt = tt;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
