int n, m; cin >> n >> m; vector<int> l(n); vector<int> r(n); for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; --l[i]; } vector<int> mu(m + 1); mu[1] = 1; for (int i = 1; i <= m; i++) { for (int j = i * 2; j <= m; j += i) { mu[j] -= mu[i]; } } int ans = 0; for (int d = 1; d <= m; d++) { if (!mu[d]) { continue; } else { int lim = m / d; int sum = 0; for (int i = 0; i < n; i++) { sum += l[i] / d + 1; } if (sum > lim) { continue; } int t = lim - sum; vector<int> f(t + 1); f[0] = 1; for (int i = 0; i < n; i++) { int v = r[i] / d - l[i] / d; for (int j = 1; j <= t; j++) { f[j] += f[j - 1]; if (f[j] >= P) { f[j] -= P; } } for (int j = t; j >= v; j--) { f[j] -= f[j - v]; f[j] += f[j] >> 31 & P; } } int cur = 0; for (int i = 0; i <= t; i++) { cur += f[i]; if (cur >= P) { cur -= P; } } if (mu[d] == 1) { ans += cur; if (ans >= P) { ans -= P; } } else { ans -= cur; ans += ans >> 31 & P; } } } cout << ans << "\n";