#include <bits/stdc++.h>
using namespace std;
int mp[105][1005 * 100] = {0}, tx[105], xx[105][105 * 105] = {0};
int main() {
  int n, s;
  scanf("%d%d", &n, &s);
  int t, vv, tt;
  for (int i = 1; i <= n; i++) {
    int k;
    t = 0;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d%d", &vv, &tt);
      for (int l = 1; l <= tt; l++) {
        mp[i][t + l] = mp[i][t + l - 1] + vv;
      }
      t += tt;
      xx[i][++xx[i][0]] = t;
    }
  }
  int num = 0, ans = 0;
  for (int j = 1; j < n; j++) {
    for (int k = j + 1; k <= n; k++) {
      int t1 = 0;
      for (int i1 = 1, i2 = 1; i1 <= xx[j][0] && i2 <= xx[k][0];) {
        int t;
        if (xx[j][i1] < xx[k][i2]) {
          t = xx[j][i1];
          i1++;
        } else {
          t = xx[k][i2];
          i2++;
        }
        if ((mp[j][t1] > mp[k][t1] && mp[j][t] < mp[k][t]) ||
            (mp[j][t1] < mp[k][t1] && mp[j][t] > mp[k][t])) {
          ans++;
        }
        if (mp[j][t] != mp[k][t]) t1 = t;
      }
    }
  }
  printf("%d\n", ans);
}
