#include <bits/stdc++.h>
using namespace std;
int n, S;
int v[101][101] = {0};
int t[101][101] = {0};
int tt1[101] = {0};
int tt2[101] = {0};
int ans = 0;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> S;
  for (int i = 1; i <= n; i++) {
    cin >> v[i][0];
    for (int j = 1; j <= v[i][0]; j++) {
      cin >> v[i][j] >> t[i][j];
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      memcpy(tt1, t[i], sizeof(tt1));
      memcpy(tt2, t[j], sizeof(tt2));
      for (int S1 = 0, S2 = 0, P1 = 1, P2 = 1;
           P1 <= v[i][0] && P2 <= v[j][0];) {
        int tmptime = min(tt1[P1], tt2[P2]);
        tt1[P1] -= tmptime;
        tt2[P2] -= tmptime;
        int NS1 = S1 + tmptime * v[i][P1];
        int NS2 = S2 + tmptime * v[j][P2];
        if (tt1[P1] == 0) P1++;
        if (tt2[P2] == 0) P2++;
        if (S1 < S2 &&
            (NS1 > NS2 || NS1 == NS2 && NS1 != S && v[i][P1] > v[j][P2]))
          ans++;
        if (S1 > S2 &&
            (NS1 < NS2 || NS1 == NS2 && NS1 != S && v[i][P1] < v[j][P2]))
          ans++;
        S1 = NS1;
        S2 = NS2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
