import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

long[10^^5] XS;
long[10^^5] VS;

void main()
{
    auto nc = readln.split.to!(long[]);
    auto N = nc[0];
    auto C = nc[1];

    foreach (i; 0..N) {
        auto xv = readln.split.to!(long[]);
        XS[i] = xv[0];
        VS[i] = xv[1];
    }

    long[10^^5] tb, tba;
    long max_v = tb[N-1] = tba[N-1] = VS[N-1] - (C - XS[N-1]);
    foreach_reverse (i; 0..N-1) {
        tb[i] = tba[i] = tb[i+1] + VS[i] - XS[i+1] + XS[i];
        if (tb[i] < max_v) {
            tba[i] = max_v;
        } else {
            max_v = tb[i];
        }
    }
    long[10^^5] tbb;
    max_v = tbb[0] = VS[0] - XS[0];
    foreach (i; 1..N) {
        auto v = tbb[i-1] - XS[i-1] + tba[i];
        if (v > max_v) max_v = v;

        tbb[i] = tbb[i-1] + VS[i] - XS[i] + XS[i-1];
        if (tbb[i] > max_v) max_v = tbb[i];
    }
    auto r1 = max_v;

    max_v = tb[0] = tba[0] = VS[0] - XS[0];
    foreach (i; 1..N) {
        tb[i] = tba[i] = tb[i-1] + VS[i] - XS[i] + XS[i-1];
        if (tb[i] < max_v) {
            tba[i] = max_v;
        } else {
            max_v = tb[i];
        }
    }
    max_v = tbb[N-1] = VS[N-1] - (C - XS[N-1]);
    foreach_reverse (i; 0..N-1) {
        auto v = tbb[i+1] - (C - XS[i+1]) + tba[i];
        if (v > max_v) max_v = v;

        tbb[i] = tbb[i+1] + VS[i] - XS[i+1] + XS[i];
        if (tbb[i] > max_v) max_v = tbb[i];
    }
    auto r2 = max_v;

    writeln(max(r1, r2, 0));
}