#include <bits/stdc++.h>
using std::cin;
using std::cout;
struct Segment {
  int x1, y1, x2, y2;
};
const int maxn = 100;
const int maxk = 100;
Segment seg[maxn][maxk];
int n, s;
int k[maxn];
void solve();
int main() {
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int v, t;
      cin >> v >> t;
      if (j == 0) {
        seg[i][j].x1 = 0;
        seg[i][j].y1 = 0;
      } else {
        seg[i][j].x1 = seg[i][j - 1].x2;
        seg[i][j].y1 = seg[i][j - 1].y2;
      }
      seg[i][j].x2 = seg[i][j].x1 + t;
      seg[i][j].y2 = seg[i][j].y1 + v * t;
    }
  }
  solve();
  return 0;
}
int cross(Segment& a, Segment& b) {
  const double ee = 1e-8;
  long long b1, b2, a11, a12, a21, a22, d, d1, d2;
  b1 = a.x1 - b.x1;
  b2 = a.y1 - b.y1;
  a11 = a.x1 - a.x2;
  a12 = b.x2 - b.x1;
  a21 = a.y1 - a.y2;
  a22 = b.y2 - b.y1;
  d = a11 * a22 - a12 * a21;
  if (d == 0) return 0;
  d1 = b1 * a22 - a12 * b2;
  d2 = a11 * b2 - b1 * a21;
  double t1, t2;
  t1 = (double)d1 / d;
  t2 = (double)d2 / d;
  if (t1 > ee && t2 > ee && t1 <= 1 && t2 <= 1) {
    if (1 - ee < t1) {
      if (1 - ee < t2)
        return 4;
      else
        return 2;
    } else if (1 - ee < t2)
      return 3;
    else
      return 1;
  }
  return 0;
}
bool theSameSide(Segment& a, Segment& b, Segment& c) {
  long long x1, y1, x2, y2, x3, y3;
  x1 = a.x1 - c.x1;
  y1 = a.y1 - c.y1;
  x2 = b.x2 - c.x1;
  y2 = b.y2 - c.y1;
  x3 = c.x2 - c.x1;
  y3 = c.y2 - c.y1;
  bool s1, s2;
  s1 = (x1 * y3 - x3 * y1 > 0);
  s2 = (x2 * y3 - x3 * y2 > 0);
  return (s1 == s2);
}
bool specialTest(Segment& a, Segment& b, Segment& c, Segment& d) {
  long long x1, y1, x2, y2, s1, s2;
  x1 = a.x1 - a.x2;
  y1 = a.y1 - a.y2;
  x2 = c.x1 - c.x2;
  y2 = c.y1 - c.y2;
  s1 = (x1 * y2 - x2 * y1 > 0);
  x1 = b.x2 - b.x1;
  y1 = b.y2 - b.y1;
  x2 = d.x2 - d.x1;
  y2 = d.y2 - d.y1;
  s2 = (x1 * y2 - x2 * y2 > 0);
  return (s1 == s2);
}
void solve() {
  int i1, j1, i2, j2;
  int total = 0;
  for (i1 = n - 1; i1 >= 0; i1--) {
    for (j1 = 0; j1 < k[i1]; j1++) {
      for (i2 = i1 - 1; i2 >= 0; i2--) {
        for (j2 = 0; j2 < k[i2]; j2++) {
          if (seg[i2][j2].x1 > seg[i1][j1].x2 ||
              seg[i2][j2].y1 > seg[i1][j1].y2)
            break;
          if (seg[i2][j2].x2 < seg[i1][j1].x1 ||
              seg[i2][j2].y2 < seg[i1][j1].y1)
            continue;
          int result = cross(seg[i1][j1], seg[i2][j2]);
          switch (result) {
            case 1:
            case 2:
            case 3:
              total++;
              break;
            case 4:
              if (j1 < k[i1] - 1 && j2 < k[i2] - 1) total++;
              break;
          }
        }
      }
    }
  }
  cout << total << '\n';
}
