void main()
{
    long n, c;
    ipElems(n, c);
    Sushi[] sushi = n.rdCol!Sushi;

    long result;

    long[] l = new long[n+1];
    long[] lrev = new long[n+1];
    long pos;
    long lrevmax, lpos;
    foreach (i, s; sushi)
    {
        l[i+1] = l[i] + s.v - s.x + pos;
        lrev[i+1] = l[i+1] - s.x;
        pos = s.x;
        result = max(result, l[i+1]);
        if (i != n - 1 && lrevmax < lrev[i+1])
        {
            lrevmax = lrev[i+1];
            lpos = i + 1;
        }
    }

    long[] r = new long[n+1];
    long[] rrev = new long[n+1];
    pos = c;
    long rrevmax, rpos = n;
    foreach_reverse (i, s; sushi)
    {
        r[i] = r[i+1] + s.v - pos + s.x;
        rrev[i] = r[i] - c + s.x;
        pos = s.x;
        result = max(result, r[i]);
        if (i != 0 && rrevmax < rrev[i])
        {
            rrevmax = rrev[i];
            rpos = i;
        }
    }

    long rmax = r[lpos+1..$].reduce!max;
    result = max(result, lrevmax+rmax);
    long lmax = l[0..rpos].reduce!max;
    result = max(result, rrevmax+lmax);

    result.writeln;
}

struct Sushi
{
    long x, v;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void ipElems(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;