#include <bits/stdc++.h>
using namespace std;
int const N = 100 + 20, K = 100 + 20;
int n, s, ans, k[N], t[N][K], v[N][K], d[2 * N];
int f(int a, int b) {
  set<int> st;
  for (int i = 0; i < k[a]; i++) st.insert(t[a][i]);
  for (int i = 0; i < k[b]; i++) st.insert(t[b][i]);
  int cur = 0, prv = 0, ret = 0, pA = 0, pB = 0, vA = 0, vB = 0, sz = 0;
  for (set<int>::iterator it = st.begin(); it != st.end(); it++) {
    cur = (*it);
    d[sz++] = (vA - vB) * (cur - prv);
    prv = cur;
    while (pA + 1 < k[a] && t[a][pA + 1] <= cur) pA++;
    while (pB + 1 < k[b] && t[b][pB + 1] <= cur) pB++;
    vA = v[a][pA];
    vB = v[b][pB];
  }
  int sum1 = 0, sum2 = 0, sum3 = 0;
  for (int i = 1; i < sz; i++) {
    sum3 = sum2, sum2 = sum1, sum1 += d[i];
    if (sum1 > 0 && sum2 < 0)
      ret++;
    else if (sum1 < 0 && sum2 > 0)
      ret++;
    else if (!sum2) {
      if (sum1 > 0 && sum3 < 0)
        ret++;
      else if (sum1 < 0 && sum3 > 0)
        ret++;
    }
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    int tme = 0, x;
    for (int j = 0; j < k[i]; j++) {
      cin >> v[i][j] >> x;
      t[i][j] = tme;
      tme += x;
    }
    t[i][k[i]++] = tme;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < i; j++) {
      ans += f(i, j);
    }
  return cout << ans, 0;
}
