#include <bits/stdc++.h>
using namespace std;
int m, n, j, k, l, i, o, p, __t;
int V[200][2000], tim[200][2000], T[200], cop[200][2000];
char ch;
void read(int &a) {
  for (ch = getchar(); (ch < '0' || ch > '9') && (ch != '-'); ch = getchar())
    ;
  if (ch == '-')
    a = 0, __t = -1;
  else
    a = ch - '0', __t = 1;
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    a = a * 10 + ch - '0';
  a *= __t;
}
int main() {
  read(m), read(n);
  for (int i = 1; i <= m; i++) {
    read(T[i]);
    for (int j = 1; j <= T[i]; j++)
      read(V[i][j]), read(tim[i][j]), cop[i][j] = tim[i][j];
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      for (int k = 1; k <= T[i]; k++) tim[i][k] = cop[i][k];
      for (int k = 1; k <= T[j]; k++) tim[j][k] = cop[j][k];
      int x0 = 0, x1 = 0, who = 0;
      if (V[i][1] > V[j][1])
        who = -1;
      else
        who = 1;
      for (int t1 = 1, t2 = 1; t1 <= T[i] && t2 <= T[j];) {
        int dece = min(tim[i][t1], tim[j][t2]);
        int y0 = x0 + dece * V[i][t1];
        int y1 = x1 + dece * V[j][t2], nexwho;
        if (y0 == y1)
          nexwho = who;
        else if (y0 < y1)
          nexwho = 1;
        else
          nexwho = -1;
        if (nexwho != who) ans++;
        who = nexwho;
        x0 = y0, x1 = y1;
        tim[i][t1] -= dece;
        tim[j][t2] -= dece;
        if (tim[i][t1] == 0) t1++;
        if (tim[j][t2] == 0) t2++;
      }
    }
  }
  cout << ans << endl;
}
