#include <bits/stdc++.h>
using namespace std;
vector < pair <int64_t , int64_t> > intervale;
int main ()
{
ios :: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int cantitate; int64_t mod_1 , mod_2;
cin >> cantitate >> mod_1 >> mod_2;
mod_1 /= __gcd(mod_1 , mod_2 + 1);
for (int indice = 1 ; indice <= cantitate ; indice++)
{
int64_t stanga , dreapta;
cin >> stanga >> dreapta;
if ((dreapta - stanga + 1) / mod_1 >= mod_2)
{ cout << mod_1 * mod_2; return 0; }
if (mod_1 <= 1000000000000000000 / mod_2)
{ stanga %= mod_1 * mod_2; dreapta %= mod_1 * mod_2; }
if (stanga <= dreapta)
{ intervale.emplace_back(stanga , dreapta); }
else
{
intervale.emplace_back(stanga , mod_1 * mod_2 - 1);
intervale.emplace_back(0 , dreapta);
}
}
sort(intervale.begin() , intervale.end());
int64_t gasit = 0;
for (int indice = 0 ; indice < (int)intervale.size() ; indice++)
{
int64_t inceput = intervale[indice].first , maxim = intervale[indice].second;
while (indice + 1 < (int)intervale.size() && intervale[indice + 1].first <= maxim)
{ maxim = max(maxim , intervale[++indice].second); }
gasit += maxim - inceput + 1;
}
cout << gasit;
return 0;
}