#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:16000000")
#pragma warning(disable : 4996)
const int inf = 1 << 25;
const double eps = 1e-9;
vector<vector<int> > t, v;
int sign(int x) { return x == 0 ? 0 : x > 0 ? 1 : -1; }
int f(int a, int b) {
  int d = v[a][0] - v[b][0];
  int i1 = 1, i2 = 1;
  int s1 = 0, s2 = 0;
  int v1 = v[a][0], v2 = v[b][0];
  int prevT = 0;
  int ret = 0;
  while (i1 < t[a].size() && i2 < t[b].size()) {
    if (t[a][i1] < t[b][i2]) {
      s1 += (t[a][i1] - prevT) * v1;
      s2 += (t[a][i1] - prevT) * v2;
      v1 = v[a][i1];
      prevT = t[a][i1++];
    } else if (t[a][i1] > t[b][i2]) {
      s1 += (t[b][i2] - prevT) * v1;
      s2 += (t[b][i2] - prevT) * v2;
      v2 = v[b][i2];
      prevT = t[b][i2++];
    } else {
      s1 += (t[b][i2] - prevT) * v1;
      s2 += (t[b][i2] - prevT) * v2;
      v1 = v[a][i1];
      v2 = v[b][i2];
      prevT = t[b][i2];
      ++i2, ++i1;
    }
    if (s1 == s2) {
      if (v1 != v2 && sign(v1 - v2) != sign(d)) ++ret, d = -d;
    } else if (sign(s1 - s2) != sign(d))
      ++ret, d = -d;
  }
  return ret;
}
int main() {
  int n, s;
  cin >> n >> s;
  t.resize(n);
  v.resize(n);
  for (int i = (0); i < (n); ++i) {
    int k;
    cin >> k;
    t[i].resize(k + 1);
    v[i].resize(k);
    t[i][0] = 0;
    for (int j = (0); j < (k); ++j)
      cin >> v[i][j] >> t[i][j + 1], t[i][j + 1] += t[i][j];
    v[i].push_back(0);
  }
  int ans = 0;
  for (int i = (0); i < (n); ++i)
    for (int j = (i + 1); j < (n); ++j) ans += f(i, j);
  cout << ans << endl;
  return 0;
}
