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[string] memo;
    long solve(long cnt, int flag, int d, long i) {
        auto v = VS[i];
        if (cnt == N) return v;

        auto key = format("%d %d %d %d", cnt, flag, d, i);
        if (key in memo) return memo[key];

        long w, x;
        w = v + solve(cnt+1, flag, d, i+d) - abs(XS[i] - XS[i+d]);

        if (flag) {
            if (d == 1) {
                x = v + solve(cnt+1, 0, -1, N-1) - (XS[i] + C - XS[N-1]);
            } else {
                x = v + solve(cnt+1, 0, 1, 0) - (C - XS[i] + XS[0]);
            }
        }

        return memo[key] = max(v, w, x);
    }

    writeln(max(solve(1, 1, 1, 0) - XS[0], solve(1, 1, -1, N-1) - (C - XS[N-1]), 0));
}