#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    int n; cin >> n;
    lint m; cin >> m;
    V<> l(n), r(n), v;
    for (int i = 0; i < n; ++i) {
        cin >> l[i] >> r[i];
        v.push_back(l[i]);
        v.push_back(r[i]);
    }
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
    for (auto&& e : l) {
        e = lower_bound(begin(v), end(v), e) - begin(v);
    }
    for (auto&& e : r) {
        e = lower_bound(begin(v), end(v), e) - begin(v);
    }

    V<> c(v.size() + 1);
    for (int i = 0; i < n; ++i) {
        ++c[l[i]];
        --c[r[i] + 1];
    }
    for (int i = 0; i < (int)v.size(); ++i) {
        c[i + 1] += c[i];
    }
    lint res = 0;
    for (int i = 0; i < (int)v.size(); ++i) {
        lint curr = -1;
        if (c[i] & 1) {
            curr = m * (c[i] - 1) + v[i];
        } else {
            curr = m * (c[i] - 1) + m - v[i];
        }
        res = max(res, curr);
    }
    cout << res << '\n';
}
