#include <bits/stdc++.h>
const int MAXT = 30300;
const int MAXN = 110;
using namespace std;
int n, s;
int veloc[MAXN][MAXT];
int a[MAXN][MAXN];
int pos[MAXN];
vector<int> T;
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  int nSegs, v, t;
  for (int i = (1); i <= (n); i++) {
    cin >> nSegs;
    int timer = 0, t;
    for (int j = (1); j <= (nSegs); j++) {
      cin >> v >> t;
      for (int k = (timer); k < (timer + t); k++) veloc[i][k] = v;
      timer += t;
      T.push_back(timer);
    }
  }
  sort((T).begin(), (T).end());
  T.resize(unique((T).begin(), (T).end()) - T.begin());
  int lastTime = 0, ans = 0;
  for (typeof((T).begin()) it = (T).begin(); it != (T).end(); ++it) {
    for (int i = (1); i <= (n); i++)
      pos[i] += (*it - lastTime) * veloc[i][lastTime];
    for (int i = (1); i <= (n); i++)
      for (int j = (i + 1); j <= (n); j++)
        if (a[i][j] != a[j][i] && pos[i] != pos[j])
          ans += a[i][j] != pos[i] > pos[j];
    for (int i = (1); i <= (n); i++)
      for (int j = (1); j <= (n); j++)
        if (pos[i] != pos[j]) a[i][j] = pos[i] > pos[j];
    lastTime = *it;
  }
  cout << ans;
  return 0;
}
