#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(0);
  solve();
  return 0;
}
int V[100][100];
int T[100][100];
int K[100];
int N, S;
void fillT(int a, vector<int>& r) {
  r.push_back(0);
  for (int i = 0; i < K[a]; i++) {
    int t = r.back();
    r.push_back(t + T[a][i]);
  }
}
vector<pair<int, int> > split(int a, vector<int>& t) {
  vector<pair<int, int> > res;
  int from = 0;
  for (int i = 0; i < K[a]; i++) {
    int v = V[a][i];
    int to = from + T[a][i];
    int j1 = lower_bound(t.begin(), t.end(), from) - t.begin();
    int j2 = lower_bound(t.begin(), t.end(), to) - t.begin();
    for (int j = j1; j < j2; j++) {
      res.push_back(make_pair(v, t[j + 1] - t[j]));
    }
    from = to;
  }
  return res;
}
int collisions(int a, int b) {
  vector<int> t;
  fillT(a, t);
  fillT(b, t);
  sort(t.begin(), t.end());
  t.resize(unique(t.begin(), t.end()) - t.begin());
  vector<pair<int, int> > one = split(a, t);
  vector<pair<int, int> > two = split(b, t);
  int n = min((int)((one).size()), (int)((two).size()));
  int res = 0;
  long long sa = 0, sb = 0;
  for (int i = 0; i < n; i++) {
    assert(one[i].second == two[i].second);
    assert(one[i].second != 0);
    long long na = sa + one[i].first * one[i].second;
    long long nb = sb + two[i].first * two[i].second;
    if (na == nb) {
      if (i < n - 1) {
        long long nna = na + one[i + 1].first * one[i + 1].second;
        long long nnb = nb + two[i + 1].first * two[i + 1].second;
        res++;
      }
    } else {
      if ((sa - sb) * (na - nb) < 0) res++;
    }
    sa = na;
    sb = nb;
  }
  assert(sa == S || sb == S);
  return res;
}
void solve() {
  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];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ans += collisions(i, j);
    }
  }
  cout << ans << '\n';
}
