#include <bits/stdc++.h>
using namespace std;
#define int long long
using ld = long double;
using pr = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
const int INF = 1e18+1, MOD = 1e9+7, MAXN = 4e5+5, MAXA = 41;
void solve() {
int n, a, b;
cin >> n >> a >> b;
vector<pr> ar(n);
for (auto& [i, j] : ar) cin >> i >> j;
// int t = 0;
// set<pr> seen;
// while (1) {
// int x = (t + t/b) % a, y = t % b;
// if (y == 0)
// cout << t << ' ' << x << ' ' << y << '\n';
// if (seen.find({x, y}) != seen.end()) {
// cout << t << '\n';
// cout << a * b << '\n';
// cout << gcd(a, b+1);
// break;
// }
// seen.insert({x, y});
// t += b;
// }
int loop = a / gcd(a, b+1) * (b);
if (loop < 0) loop = (int)(1e18+1);
vector<pr> ranges;
for (int i = 0; i < n; i++) {
auto [l, r] = ar[i];
if (r - l + 1 >= loop) {
ranges.pb({0, loop-1});
}
else {
l %= loop; r %= loop;
if (l > r) {
ranges.pb({0, r});
ranges.pb({l, loop-1});
}
else {
ranges.pb({l, r});
}
}
}
sort(ranges.begin(), ranges.end());
int l = 0, r = -1;
int res = 0;
for (auto [i, j] : ranges) {
// cout << i << ' ' << j << '\n';
if (r >= i) {
r = max(r, j);
}
else {
res += (r - l + 1);
l = i; r = j;
}
}
res += (r - l + 1);
cout << res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// int T;
// cin >> T;
// while (T--)
solve();
}