#include <bits/stdc++.h>
const int N = 100010;
const int inf = 0x3f3f3f3f;
using namespace std;
int n, s, t[110][110], v[110][110], k[110];
int main() {
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> v[i][j] >> t[i][j];
      if (j > 0) t[i][j] += t[i][j - 1];
    }
  }
  int ret = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      int p1 = 0, p2 = 0, t1 = 0, l1 = 0, l2 = 0, d1 = 0, d2 = 0;
      while (p1 < s && p2 < s) {
        int tc = 0;
        if (t[i][l1] <= t[j][l2])
          tc = t[i][l1] - t1;
        else
          tc = t[j][l2] - t1;
        p1 += v[i][l1] * tc;
        p2 += v[j][l2] * tc;
        if (1ll * (d2 - d1) * (p2 - p1) < 0) ret++;
        if (p1 != p2) d1 = p1, d2 = p2;
        if (t[i][l1] < t[j][l2])
          t1 = t[i][l1], l1++;
        else if (t[i][l1] > t[j][l2])
          t1 = t[j][l2], l2++;
        else
          t1 = t[i][l1], l1++, l2++;
      }
    }
  }
  cout << ret << endl;
  return 0;
}
