#include <bits/stdc++.h>
using namespace std;
int cell[1000001];
int main() {
  int n, s, k, i, t, q, p, j, take, counter;
  vector<vector<pair<int, int> > > cell;
  cin >> n >> s;
  pair<int, int> temp, dist;
  for ((i) = (0); (i) < (int)(n); (i)++) {
    cin >> k;
    vector<pair<int, int> > temp1;
    for ((j) = (0); (j) < (int)(k); (j)++) {
      cin >> temp.first >> temp.second;
      temp1.push_back(temp);
    }
    cell.push_back(temp1);
  }
  counter = 0;
  for ((i) = (0); (i) < (int)(n); (i)++) {
    for ((j) = (i + 1); (j) < (int)(n); (j)++) {
      if (cell[i].operator[](0).first > cell[j].operator[](0).first)
        take = i;
      else
        take = j;
      temp.first = 0;
      temp.second = 0;
      dist.first = 0;
      dist.second = 0;
      for (p = 0, q = 0; p < cell[i].size() && q < cell[j].size();) {
        if (cell[i].operator[](p).second - temp.first <
            cell[j].operator[](q).second - temp.second) {
          t = cell[i].operator[](p).second - temp.first;
          dist.first += t * cell[i].operator[](p).first;
          dist.second += t * cell[j].operator[](q).first;
          if (take == i) {
            if (dist.second > dist.first) {
              counter++;
              take = j;
            }
          } else {
            if (dist.second < dist.first) {
              counter++;
              take = i;
            }
          }
          temp.first = 0;
          temp.second += t;
          p++;
        } else {
          if (cell[i].operator[](p).second - temp.first >
              cell[j].operator[](q).second - temp.second) {
            t = cell[j].operator[](q).second - temp.second;
            dist.first += t * cell[i].operator[](p).first;
            dist.second += t * cell[j].operator[](q).first;
            if (take == i) {
              if (dist.second > dist.first) {
                counter++;
                take = j;
              }
            } else {
              if (dist.second < dist.first) {
                counter++;
                take = i;
              }
            }
            temp.first += t;
            temp.second = 0;
            q++;
          } else {
            t = cell[i].operator[](p).second - temp.first;
            dist.first += t * cell[i].operator[](p).first;
            dist.second += t * cell[j].operator[](q).first;
            if (take == i) {
              if (dist.second > dist.first) {
                counter++;
                take = j;
              }
            } else {
              if (dist.second < dist.first) {
                counter++;
                take = i;
              }
            }
            temp.first = 0;
            temp.second = 0;
            p++;
            q++;
          }
        }
      }
    }
  }
  cout << counter << endl;
  return 0;
}
